You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
on_mount inside rx.foreach that uses the loop variable crashes the page #7791
The page does not render. The error boundary shows:
An error occurred while rendering this page.
ReferenceError: x_rx_state_ is not defined
Expected behavior
The page renders, and each item fires its own event: seen:a, seen:b.
Cause
The lifecycle event compiles to a useEffect hook. The whole rx.foreach block becomes one memo component, and the hook goes to the top of that component, outside the loop. The loop variable exists only inside the .map() callback below it. Generated code (.web/app_components/...):
For the same reason, an on_mount in rx.foreach that does not use the loop variable does not crash, but it fires once for the whole list, not once per item.
Specifics
Reflex: main at 58e7128, default config (no react_compiler), reflex run --env prod
Browser: Chromium
OS: Linux
Additional context
#7694 avoids the crash only with react_compiler=True or auto_memoize=False, where it renders lifecycle events as an element inside the loop body. Default apps still need a fix. A general fix is to compile each rx.foreach item to its own component, so that every hook of the item runs inside the loop.
Activity
linear-code commentedon Nov 10, 2026
ENG-13943