fix(compiler): validate disabled-state rx.State usage structurally across compiled domains
TE
3h ago+557+557+012345678901234567890123456789-20-20-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?
Summary
Fixes #7579 by replacing the generated-JS substring guard (code_uses_state_contexts on page_ctx.output_code) in compile_app with structural validation over originating VarData metadata across all final compilation domains:
- Auto-memoized and explicit memo state reads: Auto-memoization moves stateful subtrees out of page modules into memo modules, and
Component._get_vars_hooksstrips originatingVarDatato position-only metadata when emitting hooks._compiled_app_uses_stateinspects originatingVarData.field_dependencies(walkingVars,deps,components,app_wraps, hooks, prop-embedded components, and children) after app-wrap resolution/memoization,hydrate_fallbackregistration, andMEMOSscoping. - No false positives on literal text or client-only hooks: Pages rendering literal
"useContext(StateContexts"or"useStateContext("strings,rx.client_state, or custom client-only React hooks compile cleanly underrx.App(enable_state=False). - Actionable diagnostic:
ReflexRuntimeErrornow explains thatrx.Statecannot be accessed whenenable_state=Falseis set onrx.App(since the reproduction already defines aStatesubclass).reflex.state.code_uses_state_contextsis preserved for backwards compatibility with existing callers.
Testing
- Added unit tests in
tests/units/compiler/test_compiler.pycovering auto-memoized and non-memoized state reads, explicit@rx.memobody and prop reads, prop-embedded stateful components, statefulextra_app_wraps, statefulhydrate_fallback, literal hook-spelling text, stateless/client-only hooks, and theenable_state=Truecontrol.
Fixes #7579