Skip to content

fix(svelte): keep errors written directly in a useForm input handler - #684

Merged
cpojer merged 1 commit into
voidzero-dev:mainfrom
yangshun:claude/dazzling-golick-575e7b
Nov 3, 2026
Merged

cpojer merged 1 commit into
voidzero-dev:mainfrom
yangshun:claude/dazzling-golick-575e7b

Conversation

@yangshun

@yangshun yangshun commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

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. setError already worked around this by refreshing the field's data snapshot first. Vue doesn't hit this because its watcher uses flush: 'sync'. This came up in review of #674 but predates it.

  • form.errors now returns a view whose writes take the same snapshot as setError. A direct write in the same handler as the edit survives, and an edit without a write still clears that field's stale error.
  • Writing an error before editing the field in the same handler still clears it, which matches Vue's synchronous watcher and the existing setError behavior.
  • Svelte keeps in-place editing; no setters were added.
  • The Svelte playground's form-errors email handler now writes form.errors.email directly, so the shared form-errors browser contract runs the Svelte idiom.

Tests

  • New packages/svelte/test/unit/use-form.test.ts compiles use-form.svelte.ts and 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 resolves svelte to the server build. The direct-write case fails on main and 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. 27 platform-unit files failed locally because this fresh worktree lacks generated platform files such as platform/packages/dashboard/.void/tsconfig.json. Nothing outside the platform failed. I did not run the full vp test run locally; CI runs it.

🤖 Generated with Claude Code

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>

@cpojer cpojer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍 Thank you.

@cpojer
cpojer merged commit 66cb908 into voidzero-dev:main Nov 3, 2026
18 checks passed
@yangshun
yangshun deleted the claude/dazzling-golick-575e7b branch November 3, 2026 10:55
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.

2 participants