Repository navigation
refactor: drop json5 dep, handle non-finite floats in socket parse fallback - #6339
Conversation
…llback Happy path uses native JSON.parse; the catch rewrites Python"s bare Infinity/-Infinity/NaN tokens outside string literals before retrying, so only payloads that actually contain specials pay the extra cost. NaN has no JSON literal and becomes null (matches JSON.stringify).
Greptile SummaryThis PR removes the
Confidence Score: 5/5Safe to merge; all findings are P2 style/documentation suggestions with no runtime correctness issues. The regex implementation correctly handles Python's non-finite float tokens and the string-literal-first alternation prevents false positives inside quoted values. Removing json5 is a clean, well-scoped change. Both open findings are P2: one asks for word-boundary guards that are not required for real payloads, and one notes the intentional NaN→null behavior change lacks a deprecation/changelog entry. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["Socket.io packet received (str)"] --> B["JSON.parse(str)"]
B -->|success| C["Return parsed object"]
B -->|throws| D["rewriteBareNonFiniteFloats(str)"]
D --> E["Regex: match string literals first\n(pass through unchanged)"]
E --> F["Replace bare Infinity → 1e999\n-Infinity → -1e999\nNaN → null"]
F --> G["JSON.parse(rewritten str)"]
G -->|success| H["Return parsed object\n(NaN becomes null, ±Inf preserved)"]
G -->|throws| I["Return false\n(malformed payload)"]
Reviews (1): Last reviewed commit: "refactor: drop json5 dep, handle non-fin..." | Re-trigger Greptile |
…o null Swap bare NaN for a sentinel string before JSON.parse and revive it back to a real NaN so Python-side float(nan) round-trips to the frontend.
|
Opened a focused follow-up issue and PR for docs/compatibility clarity around non-finite float behavior:\n\n- Issue: #6386\n- Follow-up PR: https://github.com/FarhanAliRaza/reflex/pull/6\n\nThe follow-up adds a user-facing docs note plus explicit compatibility intent comments in the existing special_floats integration test. |
* fix(upload): drop json5 from the upload helper PR #6339 removed json5 as a direct frontend dependency and replaced JSON5.parse in the socket decoder, but utils/helpers/upload.js kept importing it. json5 still resolved transitively (via Babel), and its browser entry point (dist/index.js) is a UMD bundle with core-js 2.6.5 embedded, so production builds shipped an obsolete runtime reachable through globalThis['__core-js_shared__']. The upload helper parsed chunks with JSON5 because the ndjson stream is produced by json_dumps, which emits bare NaN/Infinity/-Infinity tokens. #6339 already solved that for the socket decoder, so extract that logic into utils/helpers/json.js and use it from both call sites: JSON.parse on the fast path, with a rewrite-and-reparse fallback only when the payload carries non-finite floats. Tested against a real production build: before this change the emitted bundle contains __core-js_shared__, after it does not. Closes #7163 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_019AVQ7zFzj4UEysGQPwi2XK * chore: name the news fragment after the PR Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_019AVQ7zFzj4UEysGQPwi2XK * fix(upload): stop reviving user strings that match the NaN sentinel The NaN fallback swaps bare NaN for a sentinel string and revives that value back to NaN after parsing, so a payload carrying both a bare NaN and a genuine string equal to the sentinel lost the string. Pick a sentinel the payload does not already contain, so only the placeholder can survive parsing as that exact value. Also scope the node skip marker to the tests that shell out to node, so the json5 import guard still runs on a python-only checkout. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_019AVQ7zFzj4UEysGQPwi2XK * fix(upload): only rewrite non-finite tokens in JSON value positions The rewrite matched bare Infinity/NaN anywhere outside a string literal, so `{NaN: 1}` was turned into a valid object with a sentinel key instead of being rejected. Anchor each bare token to a position where JSON permits a value (document start, or after ':', ',' or '['), leaving a token anywhere else for JSON.parse to reject. The streaming upload parser depends on that rejection to tell a partial chunk from a complete one. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_019AVQ7zFzj4UEysGQPwi2XK --------- Co-authored-by: Claude <[email protected]>
…
Happy path uses native JSON.parse; the catch rewrites Python"s bare Infinity/-Infinity/NaN tokens outside string literals before retrying, so only payloads that actually contain specials pay the extra cost. NaN has no JSON literal and becomes null (matches JSON.stringify).
All Submissions:
Type of change
Please delete options that are not relevant.
New Feature Submission:
Changes To Core Features:
claoses #5820
Will also help with the lighthouse score, I think.