Repository navigation
Fix type validation for browser storage annotations - #7603
Conversation
[Medium impact] The reviewed changes appear safe to merge, with no outstanding findings. SummaryAccepts browser strings for fields annotated with
Reviews (2) · Last reviewed commit: "Assert browser storage hydration emits n..." · Reviewed by Greptile |
Merging this PR will degrade performance by 4.08%2 warnings
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing |
Upstream's browser-storage type fix (reflex-dev#7603) widened the field's plain types where _init_var also bound the field's Var. Here _bind_var does the binding, so the widening stays in _init_var, which runs once per field, and the Var binding is left to _bind_var.
Upstream's browser-storage type fix (reflex-dev#7603) widened the field's plain types where _init_var also bound the field's Var. Here _bind_var does the binding, so the widening stays in _init_var, which runs once per field, and the Var binding is left to _bind_var.
All Submissions:
Type of change
Changes To Core Features:
Changes
Hydration supplies plain strings for browser-storage vars, but fields annotated with
Cookie,LocalStorage, orSessionStoragecurrently log type errors for those values. Acceptstrwhen initializing these fields, including storage-containing unions, while preserving their annotations, defaults, persistence options, and checks for other invalid values. Assignment requires no additional runtime checks or storage-wrapper allocations.Add unit coverage for all three storage types,
Fieldwrappers, optional and union annotations, empty strings, subsequent writes, dirty tracking, unchanged storage options, and invalid integer values. Extend the existing browser-storage app to exercise hydration, event writes, persistence, and reloads.Closes #7499.
Validation
Tested on Windows with Python 3.12.10. The 465-test run covers
9aaed22c318cbfb1d71f94b4fc9a839f5fddbe9d; the final head,f9b47d3a6fb65ac535b4d2629328af3402c0b207, only strengthens the browser test's error-log assertion. Production source and unit tests are byte-identical between these revisions. The final browser check and repeated applicable hooks cover that follow-up.uv run --python 3.12 --locked pytest tests/units/test_state.py tests/units/reflex_base/event/processor/test_base_state_processor.py tests/units/compiler/test_compiler_utils.py -q: 465 passed. The run emitted Pydantic deprecation and collection warnings.uv run --python 3.12 --locked pytest tests/units/test_state.py -k storage_annotations_accept_browser_strings -q --tb=short: 18 passed, with the existingTestMixincollection warning. All applicable hooks on the four changed files passed again.UV_PYTHON=3.12 uv run --python 3.12 --locked pre-commit run --files reflex/state.py tests/units/test_state.py tests/integration/tests_playwright/test_hydration_storage.py news/+storage-annotation-hydration.bugfix.md: all applicable hooks passed, including Ruff, codespell, stub generation, Pyright, and ty. The environment-variable prefix shown here uses POSIX shell syntax.reflex_base.vars.baserecords directly and asserts that no errors occurred during hydration, event writes, and reloads.uv run --python 3.12 --locked pytest 'tests/integration/tests_playwright/test_hydration_storage.py::test_storage_annotations_hydrate_and_persist[AppHarness-chromium]' -q -o faulthandler_timeout=120: 1 passed on the final test. All applicable pre-commit hooks passed again for the changed browser test.uv run --python 3.12 --locked pytest tests/integration/tests_playwright/test_hydration_storage.py -k storage_annotations_hydrate_and_persist -q -o faulthandler_timeout=120reported 1 passed, 1 setup error. The development browser regression passed; production setup failed during React Router prerendering withPrerender: Request failed for /: The operation was aborted due to timeout. The process was interrupted after its error report. The diagnostic flag dumps stacks; it does not raise a test or prerender timeout. Final production behavior remains unverified.reflex/state.pyto upstream75a08e179390bd88826b4ed0bb3912d60facf7ccwhile keeping the same regression app and environment. The production-only node failed during setup with the same React Router prerender timeout (1 setup error, 409 seconds). The source was restored to the PR head afterward. This comparison does not validate production behavior; it shows the timeout also occurs with the original affected implementation.AppHarness.stop()waiting inbackend_thread.join()while the Uvicorn event loop remains running. The initial failure's cause is unresolved. The full browser suite and full unit suite are not claimed as passing.action_required, with no jobs run yet; remote CI is unverified.An independent automated review identified the optional/union gap, which was reproduced and fixed; the follow-up review found no remaining code issues. A separate source review of the final patch found no actionable correctness or security finding; it did not execute a full repository security audit. Production browser and expanded-suite validation remain incomplete as described above.
Implemented with assistance from OpenAI Codex. No human review or manual testing is claimed.