Repository navigation
fix(svelte): keep errors written directly in a useForm input handler - #684
Merged
Merged
Conversation
In Svelte, an input handler can edit a field and write `form.errors.field = '…'` in place. The effect that clears errors for edited fields ran after the handler, so it deleted the error the handler had just written. `setError` already avoided this by refreshing that field's snapshot first. `form.errors` is now a view whose writes take the same snapshot, so a direct write survives and an edit without a write still clears the stale error. The Svelte playground's email handler writes the error directly, so the shared form-errors browser contract covers it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In Svelte, an input handler can edit a field and write
form.errors.email = '…'in place, which is the adapter's idiom and is typed. Before this change, that error disappeared. The effect that clears errors for edited fields runs after the handler, so it deleted the error the handler had just written.setErroralready worked around this by refreshing the field's data snapshot first. Vue doesn't hit this because its watcher usesflush: 'sync'. This came up in review of #674 but predates it.form.errorsnow returns a view whose writes take the same snapshot assetError. A direct write in the same handler as the edit survives, and an edit without a write still clears that field's stale error.setErrorbehavior.form-errorsemail handler now writesform.errors.emaildirectly, so the shared form-errors browser contract runs the Svelte idiom.Tests
packages/svelte/test/unit/use-form.test.tscompilesuse-form.svelte.tsand a small host component with the Svelte compiler, then mounts them in happy-dom against Svelte's client entry. The unit project has no Svelte plugin and resolvessvelteto the server build. The direct-write case fails onmainand passes with this change.vp run --filter ./packages/svelte typecheck,vp lint,vp fmt.packages/svelte/test/integration/svelte-pages-client.test.ts -t "form field errors": 3 passed against the rebuilt preview.vp run test(affected, 543 files): 515 passed. 27platform-unitfiles failed locally because this fresh worktree lacks generated platform files such asplatform/packages/dashboard/.void/tsconfig.json. Nothing outside the platform failed. I did not run the fullvp test runlocally; CI runs it.🤖 Generated with Claude Code