Skip to content

fix(core): ignore stale form submit attempts#288

Merged
RtlZeroMemory merged 2 commits intomainfrom
codex/fix-form-submit-stale-attempt
Mar 18, 2026
Merged

fix(core): ignore stale form submit attempts#288
RtlZeroMemory merged 2 commits intomainfrom
codex/fix-form-submit-stale-attempt

Conversation

@RtlZeroMemory
Copy link
Copy Markdown
Owner

@RtlZeroMemory RtlZeroMemory commented Mar 17, 2026

Summary

  • track submit attempts so reset() cancels the in-flight submit lifecycle, not just the loading flag
  • ignore late async-validation completions and late submit rejections from canceled attempts
  • add regressions covering reset during pending submit rejection and reset during pending async-submit validation completion

Testing

  • npm run build
  • npm run lint
  • npm run typecheck
  • node scripts/run-tests.mjs --filter "form.state"
  • node scripts/run-tests.mjs --filter "form.async-validation"
  • node scripts/run-tests.mjs --filter "useForm"

Summary by CodeRabbit

  • Bug Fixes

    • reset() now cancels pending submits and async validations so late validation results or submit rejections don’t alter form state or values.
  • Tests

    • Added tests covering reset during pending submit, late async validation resolution/rejection, and canceled-submit behavior.
  • Documentation

    • Changelog updated to describe the above bug fixes and test coverage.

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c719ad77-072b-4b02-9fd1-74b4f93401d4

📥 Commits

Reviewing files that changed from the base of the PR and between bc5ca79 and 26b0376.

📒 Files selected for processing (1)
  • packages/core/src/layout/__tests__/layout.perf.test.ts

📝 Walkthrough

Walkthrough

Adds an internal attempt-tracking mechanism to ignore stale async validation results and submit rejections after a reset/canceled submit, and wires that mechanism through reset and submit flows; tests and changelog updated to reflect the behavior.

Changes

Cohort / File(s) Summary
Documentation
CHANGELOG.md
Added bug-fix notes documenting that late async validation results and submit rejections are ignored after reset() cancels a pending submit.
Tests
packages/core/src/forms/__tests__/form.async-validation.test.ts, packages/core/src/forms/__tests__/form.state.test.ts
Added tests covering canceled submit scenarios: late async validation resolution/rejection and late submit rejection after reset; assert form state, errors, and submitError remain unchanged.
Core submit logic
packages/core/src/forms/internal/submit.ts
Introduced internal AttemptRef counter; incremented on reset and submit start; added stale-attempt guards in failSubmit, finishSuccessfulSubmit, async validation handlers, and catch paths; updated createResetAction/createSubmitAction signatures to accept attemptRef.
Form wiring
packages/core/src/forms/useForm.ts
Added submitAttemptRef and passed it into reset/submit action creators to propagate attempt tracking.

Sequence Diagram(s)

sequenceDiagram
    participant User as User
    participant UseForm as UseForm
    participant SubmitAction as SubmitAction
    participant AsyncValidation as AsyncValidation
    participant FormState as FormState

    User->>UseForm: trigger submit (attempt `#1`)
    UseForm->>SubmitAction: start submit (records attempt `#1`)
    SubmitAction->>AsyncValidation: run async validation
    User->>UseForm: call reset (increments attempt -> `#2`)
    UseForm->>FormState: clear submitting state / reset values
    AsyncValidation-->>SubmitAction: late validation result (for `#1`)
    SubmitAction->>SubmitAction: compare attempts (`#1` vs `#2`)
    alt attempt is stale
        SubmitAction->>FormState: ignore result (no updates)
    else attempt is current
        SubmitAction->>FormState: apply validation / continue submit
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~28 minutes

Possibly related PRs

Poem

🐰 I count my hops, one, two, then three—
Old echoes fade when a reset sets me free.
Late results knock, but I keep the score,
Stale attempts shuffled off the floor.
Fresh forms spring up — hop, joy, and glee!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and specifically summarizes the main change: introducing mechanism to ignore stale form submit attempts when reset() is called, which directly aligns with the core objective and implementation across multiple files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-form-submit-stale-attempt
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

@RtlZeroMemory RtlZeroMemory merged commit 510e19e into main Mar 18, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant