Extract JSON parsing helper to eliminate json5 dependency
Merged
MA
3mo ago+317+317+012345678901234567890123456789-31-31-01234567890123456789
Type of change
- Bug fix (non-breaking change which fixes an issue)
Description
Completes the removal of the json5 dependency from the frontend by extracting the non-finite float parsing logic into a dedicated helper module. This fixes a regression where the upload helper was still importing json5, causing its bundled core-js 2.6.5 runtime to be embedded in production bundles.
Changes:
-
New helper module (
packages/reflex-base/src/reflex_base/.templates/web/utils/helpers/json.js):- Exports
parseJson()function that handles Python's bareNaN/Infinity/-Infinitytokens - Uses a fast path (native
JSON.parse) for well-formed payloads - Falls back to token rewriting only when parsing fails
- Includes comprehensive documentation
- Exports
-
Updated state.js:
- Removed inline non-finite float parsing logic (moved to helper)
- Imports and uses
parseJsonfrom the new helper module - Simplified socket decoder error handling
-
Updated upload.js:
- Removed
json5import - Uses
parseJsonhelper instead ofJSON5.parse()
- Removed
-
Comprehensive test coverage (
tests/units/reflex_base/templates/test_json_helper.py):- Regression test ensuring no templates import
json5 - Tests for parsing Python's non-finite float tokens
- Tests for plain JSON round-tripping
- Tests for string literal preservation
- Tests for error handling on unparseable payloads
- Regression test ensuring no templates import
-
Integration test (
tests/integration/test_prod_build_pipeline.py):- Verifies that built bundles do not contain
__core-js_shared__markers - Ensures the core-js runtime is not embedded in production assets
- Verifies that built bundles do not contain
Closes
Testing
- Added unit tests covering all parsing scenarios (non-finite floats, plain JSON, string preservation, error cases)
- Added regression test to verify no templates import
json5 - Added integration test to verify production bundles don't embed core-js
- All tests pass with Node.js available (skipped gracefully if missing)