Skip to content

fix: transform input defaults from spread #16481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

daimond113
Copy link

Fixes #16479.

The default props: defaultValue, defaultChecked for inputs were previously not renamed for SSR when set from an object spread, leading to unexpected results.

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.
  • If this PR changes code within packages/svelte/src, add a changeset (npx changeset).

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

Copy link

changeset-bot bot commented Jul 22, 2025

🦋 Changeset detected

Latest commit: 6f6a24a

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

This PR includes changesets to release 1 package
Name Type
svelte 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

Copy link
Contributor

Playground

pnpm add https://pkg.pr.new/svelte@16481

@paoloricciuti
Copy link
Member

I think value act a bit differently than what defaultValue does on the client but I'll have to check...however this doesn't fix the reported bug. defaultValue and defaultChecked: even without spreading props defaultValue and defaultChecked doesn't get SSRd (which also make me think that it was a conscious decision to exclude them in the first place...so maybe the fix is to exclude them instead of converting them).

Also this should also be applied to textarea no? Thanks for taking a stab at this.

@daimond113
Copy link
Author

The defaultValue not getting SSR'd seems like an issue as well, since the SvelteKit docs recommend writing forms with support for no JavaScript. Since the value isn't SSR'd into the HTML template, users without JavaScript will have to fill out the entire form, which is especially annoying for update forms.

@paoloricciuti
Copy link
Member

The defaultValue not getting SSR'd seems like an issue as well, since the SvelteKit docs recommend writing forms with support for no JavaScript. Since the value isn't SSR'd into the HTML template, users without JavaScript will have to fill out the entire form, which is especially annoying for update forms.

I agree...but you can also do that with a value directly...I don't think this is an unnecessary fix, was just pointing out that converting them to value and checked might not yield the desired result (I think there's some slight change in behaviour when you do so)

@daimond113
Copy link
Author

Unfortunately, value doesn't work if you use bind:value.

@daimond113
Copy link
Author

Also this should also be applied to textarea no?

I don't believe so - textarea doesn't support a value attribute in its markup.

@7nik
Copy link
Contributor

7nik commented Jul 23, 2025

According to specs we have:
prop defaultValue <-> attr value
prop value <-> input's current value with initial value of attr value

So, defaultValue should SSR into the value attribute. But into what should this SSR?:

<input value="foo" defaultValue="bar">

because they both set the same attribute value. I think value should take precedence in this case for better UX in no-JS case.

@daimond113
Copy link
Author

<input value="foo" defaultValue="bar">

I would expect this to SSR into <input value="bar"> and the value to be set to "foo" in JS.

@7nik
Copy link
Contributor

7nik commented Jul 23, 2025

But it can be done only if JS is enabled.
Plus, somebody can do

<input bind:value defaultValue="">

to allow resetting a pre-filled form into an empty one.

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.

spread defaultvalue is incorrectly ssr'd
3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy