fix(core): keep form submit callbacks in foreach scope

Draft
DE
1d ago
+161-47

All Submissions

  • Followed CONTRIBUTING.md and the agent guidelines.
  • Checked for another PR fixing this issue.

Type of change

  • Bug fix

Description

Fixes #3210. Submitting a form inside rx.foreach can raise ReferenceError: item_rx_state_ is not defined instead of sending the row's values to the backend.

The submit callback was emitted as a hook outside the loop, where the row item and index do not exist. Render it inline on the form so it closes over the row that created it. The old useCallback had no dependency array, so it already recreated its callback on each render.

Form-data collection, refs and reset behavior use the existing implementation. The legacy submit-name property remains accepted. Tests that inspected the former hook now inspect the rendered handler and retain their assertions. The component stub hash and package news fragment are updated.

Changes to core features

  • Added an explanation and regression tests.
  • Ran the affected tests locally.
  • Reviewed the patch against the contribution guidelines.

Validation

  • New unit regression: both form types fail before the fix.
  • Browser control on unchanged source: submission raises the out-of-scope item error.
  • Four headless browser cases pass: HTML/Radix forms in development/production, with state-backed rows submitted out of order. Item, index, fields and reset behavior are checked.
  • Four existing form-browser cases pass.
  • All 206 affected tests pass on Windows and Linux. All nine Linux pre-commit hooks pass, including Pyright, ty and code generation.

Remaining baseline gates

Kept as a draft. The full Linux unit run has 15,172 passes, 78 skips and one failure in the unrelated Granian backend-restart test. That same test fails on unchanged source too: recovery fails on main and in the full patched run; a separate patched control fails at the refusal step. The backend implementation and that test are untouched. Related readiness work already has an active PR, #7416.

The broad Windows run also encountered a local long-path file-creation limit, independently reproduced without importing Reflex. Two former-hook assertions from that run were updated and pass in the final affected suites. Upstream CI remains pending.

Related-work reconciliation — October 30

Related architecture work: #7690 addresses #3210 with per-item compiler scopes and is stacked on #6936. This draft keeps form-submit callbacks inline in their row scope. The maintainer's preferred compiler architecture should determine whether this focused fix is useful before or alongside that broader work.