Repository navigation
fix: coerce values typed into remote form fields, apply the .as() default only until edited - #16939
Conversation
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/7b8026fa1788bff1765d9d7ab3343d6b8d6d2535Open in |
🦋 Changeset detectedLatest commit: 7b8026f The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
…only until edited
933fc5d to
7b8026f
Compare
| */ | ||
| const read = (fallback) => | ||
| get_value() ?? | ||
| (fallback !== undefined && Object.hasOwn(context.get_dirty(), key) |
There was a problem hiding this comment.
Is it actually a problem to just read get_dirty? Seems like an overoptimization
There was a problem hiding this comment.
I had this on the first push. Figured out that reading get_dirty() subscribes the effect to the dirty = {} reassignment in the attachment, which runs after the select has initialised, so it reruns with value: undefined and select_option clears it. There are some better patterns for this, not really worth implementing, and they would all be more code just to make it a tad bit more read-ably understandable.
Since #16331 moved coercion into
coerce_form_value,handle_inputhas stored the raw string of every typed value:fields.value()reported'20'while typing and200after a reset, and an emptied number field held''instead ofundefined. Typed values are coerced again, the same way the submitter path already is.That re-exposes #15937: the default passed to
.as(type, default)was re-applied whenever the field's value becameundefinedornull, so an emptied number input, or one cleared withset(), snapped back to its default. The default now only applies until the field is dirty.defaultValueanddefaultCheckedare unchanged, so reset still restores it.dirtyis the modified signal from #16208;touchedwould drop the default on a tab-through. It is client-only, so SSR and a failed no-JS submission still render defaults. #16237 keys the same rule on key presence in the model instead. Fixes #15937.