Skip to content

Preserve lastResult errors without initialValue#1237

Open
morgan-coded wants to merge 1 commit into
edmundhung:mainfrom
morgan-coded:fix/1003-last-result-errors
Open

Preserve lastResult errors without initialValue#1237
morgan-coded wants to merge 1 commit into
edmundhung:mainfrom
morgan-coded:fix/1003-last-result-errors

Conversation

@morgan-coded

@morgan-coded morgan-coded commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

lastResult errors could be missed when initialValue was omitted.
This keeps null as the explicit reset case, while letting undefined continue through the existing initial-state path so returned errors are still picked up. I checked it with the focused repro, the @conform-to/dom node tests passing 49/49, typecheck, oxlint, oxfmt, and git diff --check.
Fixes #1003

Generated Summary

Changes

Core fix (packages/conform-dom/form.ts):
Changed the handling of result.initialValue from a falsy check to a strict null check. Now result.initialValue === null explicitly triggers a form reset, while undefined allows the form to use the computed initialValue (falling back to meta.initialValue). This allows error messages from lastResult to be preserved when initialValue is omitted.

Test coverage (packages/conform-dom/tests/form.node.test.ts):
Added a test case verifying that when initialValue is omitted, the form context correctly retains "last submission" errors after an onUpdate call.

Changeset (.changeset/quiet-errors-flow.md):
Added a patch release entry documenting that lastResult errors are preserved when initialValue is omitted.

Copilot AI review requested due to automatic review settings June 15, 2026 17:11
@changeset-bot

changeset-bot Bot commented Jun 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b4679a9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@conform-to/dom Patch
@conform-to/react Patch
@conform-to/valibot Patch
@conform-to/yup Patch
@conform-to/zod Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 35d70b05-d762-490e-a7fb-a432a2e0499c

📥 Commits

Reviewing files that changed from the base of the PR and between af2582e and b4679a9.

📒 Files selected for processing (3)
  • .changeset/quiet-errors-flow.md
  • packages/conform-dom/form.ts
  • packages/conform-dom/tests/form.node.test.ts
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (15)
  • GitHub Check: Future API Tests (ubuntu-latest, chromium, 22)
  • GitHub Check: Future API Tests (macos-latest, chromium, 22)
  • GitHub Check: Future API Tests (macos-latest, webkit, 22)
  • GitHub Check: E2E Tests (ubuntu-latest, chromium, 22)
  • GitHub Check: Release
  • GitHub Check: E2E Tests (ubuntu-latest, firefox, 22)
  • GitHub Check: E2E Tests (macos-latest, chromium, 22)
  • GitHub Check: E2E Tests (ubuntu-latest, webkit, 22)
  • GitHub Check: E2E Tests (windows-latest, chromium, 22)
  • GitHub Check: E2E Tests (macos-latest, webkit, 22)
  • GitHub Check: Typecheck
  • GitHub Check: Future API Tests (ubuntu-latest, firefox, 22)
  • GitHub Check: Future API Tests (ubuntu-latest, webkit, 22)
  • GitHub Check: Future API Tests (windows-latest, chromium, 22)
  • GitHub Check: API Tests (v1)
🧰 Additional context used
🪛 markdownlint-cli2 (0.22.1)
.changeset/quiet-errors-flow.md

[warning] 5-5: First line in a file should be a top-level heading

(MD041, first-line-heading, first-line-h1)

🔇 Additional comments (3)
packages/conform-dom/form.ts (1)

942-947: LGTM!

Also applies to: 969-969

packages/conform-dom/tests/form.node.test.ts (1)

1-35: LGTM!

.changeset/quiet-errors-flow.md (1)

1-5: LGTM!


📝 Walkthrough

Walkthrough

The report function in conform-dom/form.ts changes its result.initialValue guard from a falsy check to a strict === null check, computes a fallback via result.initialValue ?? meta.initialValue, and uses that computed value in the state update. A new node test verifies error retention when initialValue is omitted, and a changeset entry documents the patch.

Changes

lastResult error preservation fix

Layer / File(s) Summary
report null-check and initialValue fallback
packages/conform-dom/form.ts
result.initialValue === null is now the reset/early-return guard. When initialValue is undefined (omitted), the code falls back to meta.initialValue, and the state update's value field uses this computed value instead of result.initialValue directly.
Test coverage and changeset
packages/conform-dom/tests/form.node.test.ts, .changeset/quiet-errors-flow.md
Adds a Vitest suite for createFormContext that stubs document.forms, triggers onUpdate with an error lastResult but no initialValue, and asserts submissionStatus === 'error' and matching stored errors. Changeset documents the patch for @conform-to/dom.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Poem

🐇 Hop, hop — the errors stay!
No initialValue? That's okay.
A null check here, a fallback there,
The form remembers every snare.
Bugs begone, the tests say "pass!"
This little patch fixed it at last! 🌿

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: preserving lastResult errors when initialValue is omitted, which directly addresses the core issue.
Linked Issues check ✅ Passed The changes directly implement the fix for issue #1003 by modifying the report function to preserve lastResult errors when initialValue is undefined, matching the issue's requirements.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the lastResult error preservation issue: the changeset entry, the form.ts logic fix, and the test case.

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


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Preserves lastResult submission errors when initialValue is omitted by adjusting createFormContext().report() behavior and adding a regression test.

Changes:

  • Treats initialValue: null as the explicit reset signal (instead of falsy checks).
  • Adds a fallback value assignment when initialValue is omitted.
  • Adds a Vitest regression test and a changeset entry for the patch release.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
packages/conform-dom/form.ts Adjusts report() handling of initialValue to avoid resetting when omitted and to choose a fallback value.
packages/conform-dom/tests/form.node.test.ts Adds a regression test ensuring omitted initialValue doesn’t drop prior submission errors.
.changeset/quiet-errors-flow.md Documents the patch change for release notes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +942 to +947
if (result.initialValue === null) {
reset();
return;
}

const initialValue = result.initialValue ?? meta.initialValue;
isValueUpdated: false,
submissionStatus: result.status,
value: result.initialValue,
value: initialValue,
vi.unstubAllGlobals();
});

it('keeps last submission errors when initialValue is omitted', () => {
Comment on lines +16 to +29
const context = createFormContext({
formId: 'test-form',
lastResult: null,
});

context.onUpdate({
lastResult: {
status: 'error',
error: {
name: ['some error message'],
},
fields: ['name'],
},
});
@pkg-pr-new

pkg-pr-new Bot commented Jun 15, 2026

Copy link
Copy Markdown
More templates

@conform-to/dom

npm i https://pkg.pr.new/@conform-to/dom@1237

@conform-to/react

npm i https://pkg.pr.new/@conform-to/react@1237

@conform-to/valibot

npm i https://pkg.pr.new/@conform-to/valibot@1237

@conform-to/validitystate

npm i https://pkg.pr.new/@conform-to/validitystate@1237

@conform-to/yup

npm i https://pkg.pr.new/@conform-to/yup@1237

@conform-to/zod

npm i https://pkg.pr.new/@conform-to/zod@1237

commit: b4679a9

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.

Missing error messages when initialValue is undefined in the last result object

2 participants