Skip to content

Migrate frontend build from CRA to Vite - #1037

Open
Irozuku wants to merge 6 commits into
developfrom
feat/vite-migration
Open

Irozuku wants to merge 6 commits into
developfrom
feat/vite-migration

Conversation

@Irozuku

@Irozuku Irozuku commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

Moves the frontend build from Create React App to Vite. CRA is unmaintained and its webpack build was slow and produced a single large bundle. Vite gives a faster dev server and build, and is the base the upcoming modular frontend work needs.

The frontend jest suite is removed together with CRA, since jest was wired through react-scripts. yarn build is now the frontend check, locally and in CI.

No behaviour change is intended for users. Routes, pages and the backend are untouched.


Type of Change

  • Backend change
  • Frontend change
  • CI / Workflow change
  • Build / Packaging change
  • Bug fix
  • Documentation

Changes (by file)

  • DashAI/front/vite.config.mjs: new Vite config. Output stays in build/, so FRONT_BUILD_PATH, the Dockerfiles, MANIFEST.in and dashai.spec need no change. A small plugin compiles the .js files under src as JSX, because many of them contain JSX. The config is an ES module to avoid Vite's deprecated CJS Node API.
  • DashAI/front/index.html: moved from public/ to the frontend root, as Vite expects.
  • DashAI/front/package.json, yarn.lock: react-scripts, jest and testing-library removed; vite and @vitejs/plugin-react added. Scripts are now start, build, preview, lint, typecheck.
  • DashAI/front/.env.development, .env.production, src/api/api.ts, src/utils/urlUtils.js, src/hooks/useHardwareMonitor.js, src/components/models/LiveMetricsChart.jsx: REACT_APP_API_URL renamed to VITE_API_URL and read through import.meta.env.
  • DashAI/front/src/components/models/model/ModelIcon.jsx: the wildcard import of every MUI icon is replaced by a curated icon map, so the bundle no longer carries the whole icon set.
  • DashAI/front/src/components/models/SessionInfoContent.jsx: removed a duplicated task_name prop type key that esbuild reports.
  • DashAI/front/src/**/*.test.*, setupTests.js, test-utils/: deleted (81 test files).
  • .github/workflows/build-test.yaml, .github/workflows/publish.yml: removed the yarn test step.
  • update-server.sh: writes and reads VITE_API_URL in .env.production.local.
  • CONTRIBUTING.rst: frontend commands updated.

Testing (optional)

  • yarn install then yarn build in DashAI/front completes without errors.
  • yarn start serves the app on port 3000 against a running backend.
  • Run the backend and open http://localhost:8000: the built app loads and deep links such as /app/models still resolve.

Notes (optional)

  • Anyone with a local .env.production.local or .env.development.local must rename REACT_APP_API_URL to VITE_API_URL. Servers deployed with update-server.sh need --setup run once.

@Irozuku
Irozuku added this pull request to stack #1039 November 24, 2026 14:33
@Irozuku Irozuku added bug Something isn't working front Frontend work back Backend work refactor Prune and embelish code and removed back Backend work labels Nov 24, 2026
@cristian-tamblay

Copy link
Copy Markdown
Member

Review notes. I merged this branch locally with current develop (0f919307f) and tested the result.

1. Conflicts with develop

  • .github/workflows/build-test.yaml: keep develop's retention-days: 7 and drop the yarn test step.
  • src/api/component.test.ts, src/components/generative/RAG/PromptEditor.test.jsx and src/components/generative/RAG/RAGConfigPanel.test.jsx: delete them, since develop modified them after this branch deleted them.
  • Develop also added 14 jest test files after this branch was cut. They don't conflict, but they would stay behind as dead files, so please delete them in the same merge (paths under DashAI/front/src/):
  • components/generative/RAG/QueryTransformationPicker.test.jsx
  • components/generative/RAG/RagRetrieverComponentField.test.jsx
  • components/generative/RAG/TraceChunksPanel.test.jsx
  • components/generative/RAG/compositeTreeValidity.test.js
  • components/generative/RAG/traceUtils.test.js
  • components/shared/componentTree/ComponentTreeBuilder.test.jsx
  • components/shared/componentTree/ComponentTreeNodeConfig.test.jsx
  • components/shared/componentTree/componentTreeUtils.test.js
  • hooks/useComponentRegistry.test.js
  • hooks/useQueryTransformationOptions.test.js
  • pages/generative/RAGSession/advanced/CompositeRetrieverBuilder.test.jsx
  • pages/generative/RAGSession/advanced/QueryTransformationAdvancedModal.test.jsx
  • pages/generative/RAGSession/advanced/RetrieverConfigurationStep.test.jsx
  • utils/ragQueryTransformation.test.js

Please merge develop into this branch rather than rebasing it. Then propagate the result down the stack (1037 into #1038, #1038 into #1040, #1040 into #1041), so the later PRs don't carry the conflicts again. In #1041 the same build-test.yaml hunk also needs retention-days: 7.

2. Windows: .js must be served with a JavaScript MIME type (please fix in this PR)

Vite loads the app with <script type="module">, and browsers refuse a module script whose MIME type is not JavaScript. front_api.serve_files returns a FileResponse, which takes the type from mimetypes. On Windows, CPython lets the registry override .js, and some machines map it to text/plain. This is a known problem for Python servers on Windows.

I simulated it by mapping .js to text/plain in the server process:

  • CRA build: still loads (classic scripts are not strict about the MIME type).
  • Vite build: blank page, with Failed to load module script: ... MIME type of "text/plain".

Adding this to DashAI/back/api/front_api.py fixes it (verified with the same simulation):

import mimetypes

# Vite loads the app as a module script, which browsers refuse unless it comes
# with a JavaScript MIME type. On Windows, mimetypes takes .js from the
# registry, where some machines map it to text/plain.
mimetypes.add_type("text/javascript", ".js")

3. update-server.sh typo

grep VITE_API_URL"$ENV_LOCAL" is missing a space. grep gets a single argument and reads stdin, so when the script runs from a terminal it hangs on the last line, after the service restart. It should be grep VITE_API_URL "$ENV_LOCAL".

4. Heads-up for #1038: two alembic heads after merging develop

b1e5c3a7d9f2_drop_pipeline_tables.py revises d8f3b1c6e2a4, but develop's head is now 83bd5b526fac (from #1027). On develop + #1041, startup fails with "Multiple head revisions are present" and the migration code tries to back up and recreate the database.

Since b1e5c3a7d9f2 has not been released, pointing its down_revision (and the Revises: line) to 83bd5b526fac is enough. I checked that locally: a database at 83bd5b526fac upgrades, the four pipeline tables are dropped and the other data stays. Please re-run alembic heads against freshly fetched develop right before merging, because #1038's CI ran against an older develop.

What worked

  • yarn build takes about 22 s, and the bundle went from 13.8 MB to 10.1 MB.
  • yarn start works against a backend on another port.
  • The Docker frontend stage (Node 22 Alpine) builds, and the wheel ships build/assets/.
  • I toured 24 routes in headless Chrome, comparing the CRA and Vite builds: same result, no new errors.
  • On a trained model, Plotly charts render, and both websockets (live metrics, hardware monitor) receive data.
  • The ModelIcon map covers every ICON the backend declares.
  • On the whole stack merged with develop (with the two fixes above applied locally), yarn lint, yarn typecheck and yarn build pass, and the same UI tour shows no errors.

Minor: CLAUDE.md, AGENTS.md and docs/docs/build/testing.md (and its Spanish copy) still mention yarn test.

@Irozuku
Irozuku force-pushed the feat/vite-migration branch from fcde958 to 8380efb Compare November 27, 2026 16:48

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working front Frontend work refactor Prune and embelish code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants