Preserve lastResult errors without initialValue#1237
Conversation
🦋 Changeset detectedLatest commit: b4679a9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
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 |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
📜 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)
🧰 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)
📝 WalkthroughWalkthroughThe ChangeslastResult error preservation fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 minutes Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ 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. Comment |
There was a problem hiding this comment.
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: nullas the explicit reset signal (instead of falsy checks). - Adds a fallback value assignment when
initialValueis 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.
| 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', () => { |
| const context = createFormContext({ | ||
| formId: 'test-form', | ||
| lastResult: null, | ||
| }); | ||
|
|
||
| context.onUpdate({ | ||
| lastResult: { | ||
| status: 'error', | ||
| error: { | ||
| name: ['some error message'], | ||
| }, | ||
| fields: ['name'], | ||
| }, | ||
| }); |
More templates
@conform-to/dom
@conform-to/react
@conform-to/valibot
@conform-to/validitystate
@conform-to/yup
@conform-to/zod
commit: |
lastResulterrors could be missed wheninitialValuewas omitted.This keeps
nullas the explicit reset case, while lettingundefinedcontinue through the existing initial-state path so returned errors are still picked up. I checked it with the focused repro, the@conform-to/domnode tests passing 49/49, typecheck, oxlint, oxfmt, andgit diff --check.Fixes #1003
Generated Summary
Changes
Core fix (
packages/conform-dom/form.ts):Changed the handling of
result.initialValuefrom a falsy check to a strict null check. Nowresult.initialValue === nullexplicitly triggers a form reset, whileundefinedallows the form to use the computedinitialValue(falling back tometa.initialValue). This allows error messages fromlastResultto be preserved wheninitialValueis omitted.Test coverage (
packages/conform-dom/tests/form.node.test.ts):Added a test case verifying that when
initialValueis omitted, the form context correctly retains "last submission" errors after anonUpdatecall.Changeset (
.changeset/quiet-errors-flow.md):Added a patch release entry documenting that
lastResulterrors are preserved wheninitialValueis omitted.