Skip to content

fix: make form fields.value() reflect input_value passed to .as()#15690

Open
DrUse1 wants to merge 11 commits intosveltejs:mainfrom
DrUse1:fix/remote-form-value-undefined-with-default
Open

fix: make form fields.value() reflect input_value passed to .as()#15690
DrUse1 wants to merge 11 commits intosveltejs:mainfrom
DrUse1:fix/remote-form-value-undefined-with-default

Conversation

@DrUse1
Copy link
Copy Markdown

@DrUse1 DrUse1 commented Apr 9, 2026

Fixes #15707 :

<form {...test_form}>
	// not displaying 'default text'
	<p>{test_form.fields.name.value()}</p>

	// displays 'default text'
	<input {...test_form.fields.name.as('text', 'default text')} />
</form>

When calling fields.name.as('text', 'default'), the input_value was used as a display fallback in the returned props but was never accessible to fields.name.value(), which returned undefined until the user interacted with the input.

When .as() is called with an input_value, it now writes it to the cache via set_input, so get_value() can immediately return it.


Please don't delete this checklist! 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
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

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

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 9, 2026

🦋 Changeset detected

Latest commit: f28519d

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
Copy link
Copy Markdown

@DrUse1 DrUse1 closed this Apr 10, 2026
@DrUse1 DrUse1 reopened this Apr 10, 2026
Comment on lines +718 to +720
if (input_value !== undefined) {
defaults[key] = input_value;
}
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.

I think this could lead to out of sync values if the value changes in an event, and then it's read synchronously the line after

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.

Also this would not work if the code in the repro changes to this

<form {...test_form}>
	// not displaying 'default text'
	<p>{test_form.fields.name.value()}</p>
	// displays 'default text'
	<input {...test_form.fields.name.as('text', 'default text')} />
</form>

Copy link
Copy Markdown
Author

@DrUse1 DrUse1 Apr 12, 2026

Choose a reason for hiding this comment

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

I tried puting the display before the input and it still works

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I will put it like this in the test to be sure

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.

I think this only works by chance and the fact that default is not stateful makes it even more weird. What should happen in this case for example?

<form {...test_form}>
	// not displaying 'default text'
	<p>{test_form.fields.name.value()}</p>
	// displays 'default text'
	{#if show}
		<input {...test_form.fields.name.as('text', 'default text')} />
	{/if}
</form>

when show become true? What about when it become false?

I'll check with the rest of the team but I think we should probably just document this behaviour considering how weird it is.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Works for me, I’ll let you take it from here. I don't want to mess this up :)

DrUse1 added 5 commits April 12, 2026 19:03
placing value display before input
….com:DrUse1/kit into fix/remote-form-value-undefined-with-default
CAREFUL : I needed to change a pre-existing test that was failing
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.

fields.value() returning undefined when input_value is passed to .as()

2 participants