Add preview run mode#6663
Conversation
`reflex run --env dev-build` hot reloads like `dev`, but instead of running the Vite dev server it serves a freshly built (un-minified) frontend bundle mounted into the backend on a single port. Each backend hot reload re-runs the frontend build against the newly compiled output; a manual browser refresh shows changes. This trades the always-on Vite dev server's overhead for cold rebuilds while staying close to dev semantics. To keep rebuilds fast and output debuggable, dev-build disables (overridable): - JS + CSS minification (VITE_MINIFY -> build.minify / build.cssMinify) - autoprefixer (REFLEX_NO_AUTOPREFIXER, read by the generated postcss.config.js) - sourcemaps stay off (the default) Also threads VITE_MINIFY into the vite config, restricts `export --env` to dev/prod, and fixes `run`'s env parsing to honor the new value.
|
We can maybe call it |
Merging this PR will not alter performance
Comparing Footnotes
|
Greptile SummaryThis PR adds
Confidence Score: 5/5Safe to merge — the new code path is cleanly isolated, all three previously flagged issues are fixed, and the existing dev/prod paths are unchanged. The env-var propagation model is correct (vars are set in the main process before Granian spawns workers), the No files require special attention. Important Files Changed
Reviews (4): Last reviewed commit: "preview: drop internal=True on REFLEX_NO..." | Re-trigger Greptile |
- app.py: guard build.build() on hot reload so a failed frontend build keeps
serving the previous build instead of taking the backend down.
- postcss.config.js: make REFLEX_NO_AUTOPREFIXER honor falsy values ("false",
"0", "") so the override actually works; keep the autoprefixer entry on a
single line for the tailwind config rewriters.
- Send a distinct "run-dev-build" telemetry event.
- Add news fragments for reflex and reflex-base.
Per review feedback, align the new run mode's name with the frontend-ecosystem convention (Vite/Next/Nuxt 'preview').
|
Good call — renamed the mode to |
…ches what postcss.config.js reads
What
Adds a new run mode:
reflex run --env preview.It hot reloads like
dev, but instead of running the Vite dev server it serves a freshly built, un-minified frontend bundle mounted into the backend on a single port. Each backend hot reload re-runs the frontend build against the newly compiled output; a manual browser refresh shows changes.The motivation: get dev-like iteration without the overhead of an always-running Vite server, while serving output much closer to a real production bundle (useful for reproducing "works in dev, breaks in prod" issues).
How
Env.PREVIEWvalue, surfaced throughrun --env(and excluded fromexport --env, which stays dev/prod)._run_preview()reuses the existing prod static-mount path on a dev/reload backend — single process, no Vite.App.__call__re-runsbuild.build()(gated on preview mode + the frontend being mounted), wrapped so a build failure keeps serving the previous build instead of taking the backend down.To keep cold rebuilds fast and the output debuggable, preview flips a few defaults (all overridable via env vars):
VITE_MINIFY→build.minify/build.cssMinifyREFLEX_NO_AUTOPREFIXER, read by the generatedpostcss.config.jsVITE_SOURCEMAPThese came out of profiling: on a normal app the cold build is ~1.8s, dominated by toolchain startup, PostCSS/autoprefixer over the stylesheet, and react-router's SPA
index.htmlstep. The flips above shave ~0.3s (~15%) and land preview around ~1.5s.Notes
postcss.config.jsautoprefixer toggle keeps theautoprefixer:entry on a single line so the tailwind v3/v4 config rewriters' line-based parsing stays valid; postcss-load-config disables a plugin whose value isfalse. Existing apps pick this up on their next reinit.vite build --watchwas evaluated as a faster alternative but rejected: it doesn't generate the SPAindex.htmland reintroduces a persistent process, defeating the goal.Tests
Envround-trip (incl.preview),is_prod_mode()stays False in preview.minify/cssMinifyfromVITE_MINIFY.ruff,pyright, and unit tests pass.Follow-ups (not in this PR)
--env preview.