fix: address frontend template, visibility, and storage error follow-ups (#7869)
MI
3h ago+723+723+012345678901234567890123456789-77-77-01234567890123456789
All Submissions:
- Have you followed the guidelines stated in CONTRIBUTING.md file?
- Have you checked to ensure there aren't any other open Pull Requests for the desired changed?
Type of change
- Bug fix (non-breaking change which fixes an issue)
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?
Summary
Fixes #7869 (follow-ups from #7794):
-
Prefer
packages/reflex-frontend/srcin a source checkout (reflex_base/constants/base.py,packages/reflex-base/hatch_build.py)- Updated
_web_template_dir(root_dir)to preferpackages/reflex-frontend/srcwhenutils/state.jsexists there, and to requireutils/state.jsinside.templates/webbefore treating it as an embedded copy (so leftover directories such as.templates/web/.DS_Storeor stale files in a checkout never shadow the frontend package). - Updated
FrontendBuildHookinpackages/reflex-base/hatch_build.pyto also requireutils/state.jswhen checking for an sdist's embedded copy. - Updated
tests/units/reflex_base/constants/test_base.pyand added regression tests intest_base.pyandtests/units/test_build_config.py.
- Updated
-
Remove dead visibility branch and keep cleanup next to the socket ref (
packages/reflex-frontend/src/utils/state.js)- Removed the unreachable
if (!socket.current)self-removal branch fromcheckVisibility. - Stopped mutating
socket.current.stopWatchingVisibilityonto thesocket.io-clientSocketinstance:connect()now attaches thevisibilitychangelistener only ifsocket.currentis still the active socket afterawait socket.current.reconnect()and returns the cleanup callback, whichuseEventLoopstores in astopWatchingVisibilityref alongside thesocketref and invokes before clearingsocket.current. - Updated
packages/reflex-frontend/tests/state_connection.test.jsand added a regression test for unmounting mid-connect.
- Removed the unreachable
-
Surface a clear browser-storage-blocked connection error (
packages/reflex-base/src/reflex_base/constants/event.py,packages/reflex-frontend/src/utils/state.js,packages/reflex-components-core/src/reflex_components_core/core/banner.py)- Added
ClientErrorType.STORAGE_BLOCKED = storage_blockedand matchingERROR_TYPE_STORAGE_BLOCKEDinstate.js. - Wrapped
sessionStorage/localStorageaccess ingetToken,setToken(SecurityError), andhydrateClientStorageto throw astorage_blocked-codedError(preserving the underlyingcause) telling the user that site storage is blocked by the browser and to allow cookies/site data and reload; guarded optionallocalStoragerefresh-hint accesses inreconnectandsession_tokenerror handling, and reportednew_tokenstorage errors viasetConnectErrorsinstead of rejecting. - Added
has_storage_blocked_errorinbanner.py, handled it immediately (before the 2-error threshold, without claiming the server is unreachable) inConnectionToaster, and handled bothhas_storage_blocked_errorandhas_hydration_payload_errorindefault_connection_error()/ConnectionModal. - Added/updated unit tests in
tests/units/components/core/test_banner.py,tests/units/test_app.py,tests/units/compiler/state_js.test.mjs,packages/reflex-frontend/tests/state.test.js, andpackages/reflex-frontend/tests/state_connection.test.js.
- Added
Local Verification
- Frontend (
packages/reflex-frontend):npm run check(biome lint,tsc -p tsconfig.json,tsc -p tsconfig.node.json,vitest run: 10 files / 219 passed),biome format,npm run build(npm pack) - Python targeted suites:
pytest tests/units/reflex_base/constants/ tests/units/components/core/test_banner.py tests/units/compiler/test_state_js_template.py tests/units/test_build_config.py tests/units/test_app.py(497 passed, 2 skipped) and broaderpytest tests/units/reflex_base/ tests/units/components/ tests/units/compiler/ tests/units/test_app.py(8718 passed, 38 skipped) - Linters & type checks:
ruff check .,ruff format --check .,codespell,make_pyi.py --check,pyright --pythonplatform Linux(touched packages & tests),ty check --python-version 3.14 tests/type_checking,pyright --pythonversion 3.11/3.14 tests/type_checking,reflex-release sync --check,reflex-release changelog-check,reflex-release check-headings