Repository navigation
fix(core): keep form submit callbacks in foreach scope - #7687
DevChiniwala wants to merge 1 commit into
Conversation
A form submit handler generated as a hoisted useCallback cannot see the item or index bound by a nested foreach map. Render the same handler body inline on the form, retaining its event/ref/reset VarData, so the callback closes over its row. The former hook had no dependency array and recreated its function on each render already. Keep the legacy submit-name property accepted rather than removing a component prop in this bug fix. Cover both item/index captures with a regression that fails on the old handler. Extend the existing form app for state-backed row submissions in development/production with both HTML and Radix forms; check out-of-order submissions, fields and reset behavior. The unchanged component produces an out-of-scope item ReferenceError. All four new browser cases and four existing form-browser cases pass with the fix. The existing literal-loop generated-JavaScript control also retains all three row indices. Move existing hook-location assertions to the rendered handlers, retaining control-ref and extra-event checks. Check the order of appended events. All 206 affected tests pass on Windows and Linux. All nine full Linux pre-commit hooks pass, including codegen, Pyright and ty. The broader Linux run has 15,172 passing tests, 78 skips and one unrelated backend-restart failure. Unchanged source fails at its recovery assertion too; a separate patched isolation run fails at the refusal assertion. The backend source and test match main byte-for-byte. Do not weaken or skip them. Related backend-readiness work already has active PR reflex-dev#7416. The initial broader Windows run had 14,147 passes, 83 skips, two tests inspecting the old hooks (now updated and passing in the affected suite), and a long-path file-creation failure. A standalone file-I/O control reproduces the local OS limit without importing Reflex. Native Windows aggregate typechecking also reports unrelated platform/private-import diagnostics; the full Linux presubmit passes. Fixes reflex-dev#3210.
[Medium impact] The PR appears safe to merge; no actionable issues were found. SummaryForm submit handlers now render inline, keeping each row’s item and index available inside
Reviews (1) · Last reviewed commit: "fix(core): keep form submit callbacks in..." · Reviewed by Greptile |
|
@masenf — this addresses #3210, which you confirmed still affected 0.9.2. Both HTML and Radix forms now retain the row item and index; browser tests cover state-backed rows in development and production, submitted out of order with their form fields and reset behavior. All 206 affected tests pass on Windows and Linux, the four new and four existing browser cases pass, and all Linux pre-commit hooks pass. Greptile's review found no actionable issues. I am keeping this draft because the broader unit run encounters the existing Granian restart-test failure described in the PR. The unchanged component reproduces the foreach error; unchanged backend code reproduces the separate backend failure. The backend source/test are untouched, and related work already has #7416. Fork CI still needs approval. Guidance on that baseline gate would help complete validation. Prepared with Codex assistance. |
All Submissions
CONTRIBUTING.mdand the agent guidelines.Type of change
Description
Fixes #3210. Submitting a form inside
rx.foreachcan raiseReferenceError: item_rx_state_ is not definedinstead 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
useCallbackhad 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
Validation
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.