Skip to content
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

fix: convert input value to number on hydration #14349

Merged
merged 3 commits into from
Nov 19, 2024

Conversation

santiagocezar
Copy link
Contributor

further fixes #1755 when input is of type "number", currently the binding is set to a string if the default doesn't match.

this gets triggered frequently on Firefox, as it restores input values immediately after a refresh, before the content gets hydrated.

Copy link

changeset-bot bot commented Nov 18, 2024

🦋 Changeset detected

Latest commit: 45fa6b7

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

@Rich-Harris
Copy link
Member

preview: https://svelte-dev-git-preview-svelte-14349-svelte.vercel.app/

this is an automated message

@trueadm
Copy link
Contributor

trueadm commented Nov 19, 2024

Is this something we can capture with a test case or is it specific to FF?

Copy link
Contributor

Playground

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

@santiagocezar
Copy link
Contributor Author

looked a bit into the tests, probably a mix between hydration/samples/input-value-changed and hydration/samples/binding-input but with type="number"

@santiagocezar
Copy link
Contributor Author

santiagocezar commented Nov 19, 2024

and that's easier said than done, the only way i could find to change the input.value before the hydration step was this absolute hack:

export default test({
	props: {
		value: 2
	},

	snapshot(target) {
		const input = target.querySelector('input')
		if (input) input.value = "4"
		return {
			input,
			p: target.querySelector('p')
		};
	},

	test(assert, target, _, component, window) {
		assert.equal(component.value, 4);
	}
});

Copy link
Member

@Rich-Harris Rich-Harris left a comment

Choose a reason for hiding this comment

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

thanks!

@Rich-Harris Rich-Harris merged commit 012166e into sveltejs:main Nov 19, 2024
10 checks passed
@github-actions github-actions bot mentioned this pull request Nov 19, 2024
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.

Hydration clobbers input into form
3 participants