Skip to content

Write package.json in bun's layout - #7812

Merged
FarhanAliRaza merged 3 commits into
mainfrom
fix/package-json-stable-format
Nov 11, 2026
Merged

FarhanAliRaza merged 3 commits into
mainfrom
fix/package-json-stable-format

Conversation

@masenf

@masenf masenf commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Description

Found in the reflex 0.11.0a1 pre-release testing (FINDING-029).

Reflex wrote .web/package.json as compact one-line JSON, and reflex.lock/package.json is a byte copy of that file. Whenever bun add changes the file, bun rewrites it 2-space indented. The persisted file therefore flipped between the two layouts and produced VCS diffs with no content change.

Every package.json writer now produces bun's layout:

  • reflex_base.compiler.templates.package_json_template, which initialize_package_json and sync_root_package_json_to_web use
  • frontend_skeleton.update_package_json_overrides

The layout is json.dumps(..., indent=2, ensure_ascii=False) + "\n", written as UTF-8 with newline="\n", so Windows writes LF like bun does. bun writes non-ASCII characters as raw UTF-8 rather than \uXXXX escapes. For that reason every package.json reader now uses encoding="utf-8": _read_package_json_object, js_runtimes._existing_web_package_sections and exec.get_package_json_and_hash. A file that is not valid UTF-8 is treated as unusable, the same as invalid JSON. The persisted copy is made with path_ops.cp, so it gets the same layout.

Checked against bun 1.4.4, the version reflex pins:

  • bun add on a reflex-rendered file changes only the entries it adds. Its output equals json.dumps(json.loads(out), indent=2, ensure_ascii=False) + "\n".
  • bun keeps whatever trailing newline the file already has. An indented file goes through bun add and bun remove byte-identical.
  • bun keeps arrays expanded when they start expanded, which is how reflex writes them.

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Every test below fails on main and passes with this change. Most of them run under a new windows_text_io fixture in tests/units/conftest.py. When no encoding or newline is given, the fixture makes text-mode file access decode as ASCII and translate LF to CRLF on writes.

  • tests/units/utils/test_frontend_skeleton.py:
    • test_rendered_package_json_matches_bun_format and test_update_package_json_overrides_matches_bun_format: layout, UTF-8, and no \r in the file.
    • test_sync_root_package_json_repairs_unusable_file[\xff{}]: a non-UTF-8 file is repaired instead of raising.
  • tests/units/utils/test_exec.py::test_get_package_json_and_hash_reads_utf8
  • tests/units/utils/test_js_runtimes.py::test_existing_web_package_sections_reads_utf8

test_frontend_skeleton.py, test_exec.py, test_js_runtimes.py, test_prerequisites.py and tests/units/compiler pass, and ruff, ruff format, pyright and pre-commit are clean on the changed files.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Dxjadq3qkhKnqZR2b9WBFi

Reflex rendered .web/package.json (persisted byte-for-byte to
reflex.lock/package.json) as compact one-line JSON, while bun rewrites it
2-space indented whenever `bun add` changes it, so the persisted file flipped
between the two layouts and produced content-free VCS diffs.

Render it with `indent=2`, a trailing newline and raw UTF-8 (bun does not
escape non-ASCII) in `package_json_template` and
`update_package_json_overrides`, writing and reading the file as UTF-8. bun
keeps the file's trailing newline, so a `bun add` now changes only the
entries it adds, not the layout.

Found in the reflex 0.11.0a1 pre-release testing (FINDING-029).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dxjadq3qkhKnqZR2b9WBFi
@masenf
masenf requested a review from a team as a code owner November 11, 2026 09:12
@masenf masenf added this to the v0.11.0 milestone Nov 11, 2026
@masenf masenf added the on deck PRs lined up to review / merge next label Nov 11, 2026
@greptile-apps

greptile-apps Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issues were found.

Summary

This PR writes package.json with Bun-style indentation, raw UTF-8, and LF newlines to avoid whitespace-only changes.

  • Reflex writes package.json files in the layout Bun keeps.

Reviews (3) · Last reviewed commit: "Treat a non-UTF-8 .web/package.json as u..." · Reviewed by Greptile

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 5 files

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread reflex/utils/frontend_skeleton.py Resolved
Comment thread reflex/utils/frontend_skeleton.py Resolved
Review follow-ups for writing package.json in bun's layout:

- Read package.json as UTF-8 in `get_package_json_and_hash` and
  `_existing_web_package_sections` too. Now that reflex writes raw UTF-8,
  their locale-encoding reads raise `UnicodeDecodeError` on a cp1252 Windows
  locale for non-ASCII content.
- Treat a package.json that is not valid UTF-8 as unusable in
  `_read_package_json_object`, like invalid JSON, instead of raising.
- Write package.json with `newline="\n"`, so Windows writes LF like bun does
  instead of CRLF.
- Classify the changelog fragments as bugfix.

The tests run the readers and writers under a `windows_text_io` fixture that
gives text-mode file access the defaults of a Windows locale.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dxjadq3qkhKnqZR2b9WBFi
@codspeed

codspeed Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Merging this PR will regress 1 benchmark

2 warnings

⚠️ 19 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ 2 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚡ 1 improved benchmark
❌ 1 regressed benchmark
✅ 149 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_state_access[read_cached_computed] 45.1 ms 47 ms -4.13%
⚡ test_route_matching[10] 53.6 µs 50.5 µs +5.97%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing fix/package-json-stable-format (5f0f47c) with main (f0088e0)

Open in CodSpeed

masenf pushed a commit that referenced this pull request Nov 11, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dxjadq3qkhKnqZR2b9WBFi
@masenf

masenf commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

CodSpeed is red here on test_process_event_burst_independent_tokens[1] (-4.7%), but this PR doesn't cause it. That benchmark shows the same 4–5% drop on every PR in this batch, and the previous run on this branch (740212e) reported no change. This PR only changes how package.json is written and read during reflex init / frontend setup; event processing never touches it. CodSpeed is not a required check; leaving it for acknowledgement on CodSpeed.


Generated by Claude Code

_existing_web_package_sections read the file as UTF-8 but caught only
JSONDecodeError and OSError, so a file that is not valid UTF-8 raised a
traceback during the frontend install instead of the usual warning.

Also route the three package.json writes through one _write_package_json
helper so the UTF-8 / LF write mode is defined once.
masenf pushed a commit that referenced this pull request Nov 11, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dxjadq3qkhKnqZR2b9WBFi
@FarhanAliRaza
FarhanAliRaza merged commit f13348a into main Nov 11, 2026
167 of 168 checks passed
@FarhanAliRaza
FarhanAliRaza deleted the fix/package-json-stable-format branch November 11, 2026 16:39
masenf added a commit that referenced this pull request Nov 11, 2026
* Write package.json in bun's layout

Reflex rendered .web/package.json (persisted byte-for-byte to
reflex.lock/package.json) as compact one-line JSON, while bun rewrites it
2-space indented whenever `bun add` changes it, so the persisted file flipped
between the two layouts and produced content-free VCS diffs.

Render it with `indent=2`, a trailing newline and raw UTF-8 (bun does not
escape non-ASCII) in `package_json_template` and
`update_package_json_overrides`, writing and reading the file as UTF-8. bun
keeps the file's trailing newline, so a `bun add` now changes only the
entries it adds, not the layout.

Found in the reflex 0.11.0a1 pre-release testing (FINDING-029).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dxjadq3qkhKnqZR2b9WBFi

* Read and write package.json as UTF-8 with LF newlines everywhere

Review follow-ups for writing package.json in bun's layout:

- Read package.json as UTF-8 in `get_package_json_and_hash` and
  `_existing_web_package_sections` too. Now that reflex writes raw UTF-8,
  their locale-encoding reads raise `UnicodeDecodeError` on a cp1252 Windows
  locale for non-ASCII content.
- Treat a package.json that is not valid UTF-8 as unusable in
  `_read_package_json_object`, like invalid JSON, instead of raising.
- Write package.json with `newline="\n"`, so Windows writes LF like bun does
  instead of CRLF.
- Classify the changelog fragments as bugfix.

The tests run the readers and writers under a `windows_text_io` fixture that
gives text-mode file access the defaults of a Windows locale.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dxjadq3qkhKnqZR2b9WBFi

* Treat a non-UTF-8 .web/package.json as unreadable in the package check

_existing_web_package_sections read the file as UTF-8 but caught only
JSONDecodeError and OSError, so a file that is not valid UTF-8 raised a
traceback during the frontend install instead of the usual warning.

Also route the three package.json writes through one _write_package_json
helper so the UTF-8 / LF write mode is defined once.

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Farhan <www.mfarvirus@gmail.com>
(cherry picked from commit f13348a)
masenf pushed a commit that referenced this pull request Nov 11, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dxjadq3qkhKnqZR2b9WBFi
@masenf masenf added the release-train Issues found during agentic /prerelease-testing fanout, not necessarily validated bugs. label Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

on deck PRs lined up to review / merge next release-train Issues found during agentic /prerelease-testing fanout, not necessarily validated bugs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants