Repository navigation
Description
Describe the bug
Since reflex 0.9.8 (#6792, for #6765) sync_root_package_json_to_web() in reflex/utils/frontend_skeleton.py re-renders .web/package.json from the persisted reflex.lock/package.json and decides whether anything changed by comparing the rendered text with the file on disk:
rendered = _compile_package_json()
if output_path.exists() and output_path.read_text() == rendered:
return False
...
output_path.write_text(rendered)
return changedThe rendered text is one-line json.dumps output. But the previous install step ended with bun add … (or npm add …), and the package manager rewrites package.json in its own layout (2-space indent, its own key order), which sync_web_lockfiles_to_root() then persists. On the next compile the two strings never match even though the JSON content is identical, so:
sync_root_package_json_to_web()reports a change and rewrites.web/package.json;_sync_root_lockfiles_for_frontend_install()(reflex/utils/js_runtimes.py) seessync_root_lockfiles_to_web()returnTrueand deletes.web/reflex.install_frontend_packages.cached;- the
@cached_procedurearound_install_frontend_packagesfinds no marker and runs the whole install again:bun install --frozen-lockfile,bun add -d <dev pins>,bun add <pins>; - bun rewrites
package.jsonin its layout,sync_web_lockfiles_to_root()persists it, and the cycle repeats on the next compile, including every hot reload.
On 0.9.6 / 0.9.7 package.json was byte-copied both ways, so the two copies converged, the cache marker survived, and the package manager only ran when the dependency set actually changed. main (7cac2fa) still has the text comparison.
To Reproduce
Clean app directory (no .web, no reflex.lock), bun on PATH. Build the app, add_page, call app() three times (forking the RegistrationContext in between), with frontend_skeleton.sync_root_lockfiles_to_web and processes.run_process_with_fallbacks wrapped to print. reflex 0.9.9 (identical on 0.9.12a1):
=== compile #1 ===
sync_root_lockfiles_to_web() -> False
bun add --legacy-peer-deps -d [email protected] [email protected] @react-router/...
bun add --legacy-peer-deps [email protected] [email protected] react@19...
=== compile #2 === (nothing changed)
sync_root_lockfiles_to_web() -> True
bun add --legacy-peer-deps -d [email protected] [email protected] @react-router/...
bun add --legacy-peer-deps [email protected] [email protected] react@19...
rendered == on-disk text? False same JSON? True
=== compile #3 === (same as #2)
Same script on reflex 0.9.6: compiles #2 and #3 report False and run no package-manager command at all.
Equivalent from the CLI: reflex run --loglevel debug, touch a Python file, and watch Installing frontend packages / bun add on every reload.
Impact
With bun installed each of the three calls is ~10 ms on a warm cache, so it mostly goes unnoticed. Without bun on PATH reflex falls back to npm, where the same calls cost seconds each. reflex-enterprise's unit suite compiles an app per test in one module; on GitHub runners (no bun) that job went from 1 min 37 s on reflex 0.9.6 to 7 min 27 s on 0.9.9 and 0.9.12a1, all of it in that module: 0.9.6 job vs 0.9.9 job.
Expected behavior
Compare the persisted / rendered package.json with the on-disk one structurally, not as text: parse both and return False (without rewriting) when the objects are equal; only rewrite and report a change when the parsed content differs. That keeps #6765's goal (a damaged root copy cannot remove the required scripts), since a missing entry is a structural difference, while a package manager reformatting the file is not. Rendering in the package manager's canonical layout would also work, but bun and npm format differently, so structural comparison is the robust option.
Specifics
- Python Version: 3.13
- Reflex Version: 0.9.8 through 0.9.12a1 (0.9.6 and 0.9.7 unaffected)
- OS: Linux (locally and on ubuntu-24.04 GitHub runners)
Activity
linear-code commentedon Sep 21, 2026
ENG-12602