fix(compiler): validate disabled-state rx.State usage structurally across compiled domains

TE
3h ago
+557-20

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_hooks strips originating VarData to position-only metadata when emitting hooks. _compiled_app_uses_state inspects originating VarData.field_dependencies (walking Vars, deps, components, app_wraps, hooks, prop-embedded components, and children) after app-wrap resolution/memoization, hydrate_fallback registration, and MEMOS scoping.
  • 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 under rx.App(enable_state=False).
  • Actionable diagnostic: ReflexRuntimeError now explains that rx.State cannot be accessed when enable_state=False is set on rx.App (since the reproduction already defines a State subclass). reflex.state.code_uses_state_contexts is preserved for backwards compatibility with existing callers.

Testing

  • Added unit tests in tests/units/compiler/test_compiler.py covering auto-memoized and non-memoized state reads, explicit @rx.memo body and prop reads, prop-embedded stateful components, stateful extra_app_wraps, stateful hydrate_fallback, literal hook-spelling text, stateless/client-only hooks, and the enable_state=True control.

Fixes #7579