Skip to content

fix: coerce values typed into remote form fields, apply the .as() default only until edited - #16939

Merged
elliott-with-the-longest-name-on-github merged 1 commit into
version-3from
as-default-until-edited
Aug 27, 2026
Merged

elliott-with-the-longest-name-on-github merged 1 commit into
version-3from
as-default-until-edited

Conversation

@Nic-Polumeyv

@Nic-Polumeyv Nic-Polumeyv commented Aug 26, 2026 •

Copy link
Copy Markdown
Member

Since #16331 moved coercion into coerce_form_value, handle_input has stored the raw string of every typed value: fields.value() reported '20' while typing and 200 after a reset, and an emptied number field held '' instead of undefined. 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 became undefined or null, so an emptied number input, or one cleared with set(), snapped back to its default. The default now only applies until the field is dirty. defaultValue and defaultChecked are unchanged, so reset still restores it. dirty is the modified signal from #16208; touched would 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.

@pkg-svelte-dev

pkg-svelte-dev Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from 7b8026f:

pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/7b8026fa1788bff1765d9d7ab3343d6b8d6d2535

Open in pkg.svelte.dev: https://pkg.svelte.dev/repos/kit/pr/16939

@changeset-bot

changeset-bot Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7b8026f

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

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit 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

@svelte-docs-bot

ghost commented Aug 26, 2026

Copy link
Copy Markdown

@Nic-Polumeyv Nic-Polumeyv changed the title fix: apply the default given to .as() only until the field is edited fix: coerce values typed into remote form fields, apply the .as() default only until edited Aug 26, 2026
@Nic-Polumeyv
Nic-Polumeyv force-pushed the as-default-until-edited branch from 933fc5d to 7b8026f Compare August 26, 2026 03:48

ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just one nit, looks good otherwise

*/
const read = (fallback) =>
get_value() ??
(fallback !== undefined && Object.hasOwn(context.get_dirty(), key)

ghost Aug 26, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it actually a problem to just read get_dirty? Seems like an overoptimization

ghost Aug 26, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

ghost Aug 27, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah that's fine then

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.

Using a remote number form field with a default value stops you from completely deleting the field value

2 participants