Repository navigation
fix(compiler): validate disabled-state rx.State usage structurally across compiled domains - #7965
Conversation
…ross compiled domains Replace the JS substring check in compile_app with structural VarData state-dependency inspection across compiled pages, app wraps, explicit and automatic memos, prop-embedded components, hydrate fallbacks, and document head entries, and explain enable_state=False in the raised ReflexRuntimeError. Fixes reflex-dev#7579
[Medium impact] The change affects frontend compilation when an app disables state. The implementation has no established functional blocker, but the required test assertions and news fragment must be fixed before merging. FindingsSummaryReplaces the generated-JavaScript substring check with a walk through originating
Reviews (1) · Last reviewed commit: "fix(compiler): validate disabled-state r..." · Reviewed by Greptile |
| app = rx.App(enable_state=False) | ||
| app.add_page(lambda: rx.text(DynState.label), route="/") | ||
|
|
||
| with pytest.raises(ReflexRuntimeError, match=r"enable_state=False"): |
There was a problem hiding this comment.
Tests miss broken error messages
The new error tests match only enable_state=False, so they still pass if the explanation or suggested fix is wrong. The repository guide explicitly requires complete error-message comparisons. Capture the exception and compare its full message before merging. The same pattern appears at lines 2474 and 2517, and elsewhere in the new tests.
Context Used: CLAUDE.md (source)
| if app._state is None and _compiled_app_uses_state( | ||
| pages=( | ||
| page_ctx.root_component for page_ctx in compile_ctx.compiled_pages.values() | ||
| ), | ||
| app_root=app_root, | ||
| memos=all_memos, | ||
| head_components=app.head_components, | ||
| extra_vars=( | ||
| app.html_lang, | ||
| *(app.html_custom_attrs.values() if app.html_custom_attrs else ()), | ||
| ), |
There was a problem hiding this comment.
This changes which apps fail compilation and replaces the error shown to users, but the PR adds no news/ fragment. The repository guide requires one for user-facing changes. Before merging, add a root news/+<slug>.bugfix.md entry describing the disabled-state check and the corrected handling of literal text.
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
All Submissions:
Type of change
Changes To Core Features:
Summary
Fixes #7579 by replacing the generated-JS substring guard (
code_uses_state_contextsonpage_ctx.output_code) incompile_appwith structural validation over originatingVarDatametadata across all final compilation domains: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."useContext(StateContexts"or"useStateContext("strings,rx.client_state, or custom client-only React hooks compile cleanly underrx.App(enable_state=False).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
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