Skip to content

Conversation

Rich-Harris
Copy link
Member

@Rich-Harris Rich-Harris commented Oct 6, 2025

This closes a TODO, and insodoing fixes an actual bug — if you edit a form that contains a select, the value getter will re-run (because input has changed) and nuke the select because the model value is typically undefined to start with.

Unfortunately it doesn't quite work, because an effect doesn't depend on the $derived values that were created inside it. So when you do {field.value()}, you're creating a derived and then immediately (trying to) depend on it. I'm not immediately sure what footwork would be required to work around that, or if it indicates that it should be possible for an effect to depend on a derived it created. So I'm leaving this in draft for now.


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.

Copy link

changeset-bot bot commented Oct 6, 2025

🦋 Changeset detected

Latest commit: 350acd2

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

@Rich-Harris
Copy link
Member Author

Worked around it with a time-worn hack: maintaining a set of version sources created outside the effects in question

@Rich-Harris Rich-Harris marked this pull request as ready for review October 6, 2025 17:23
@Rich-Harris
Copy link
Member Author

As @dummdidumm just noted elsewhere, the $derived thing does work when experimental.async is true, but only then (because we changed the behaviour around deriveds in async mode for exactly this reason). But the solution in 1cd0ab4 works in both cases

@Rich-Harris Rich-Harris changed the title fix: use $derived for form fields fix: granular updates of field.value() Oct 7, 2025
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
@Rich-Harris Rich-Harris merged commit 874450a into main Oct 7, 2025
19 of 20 checks passed
@Rich-Harris Rich-Harris deleted the derived-form-values branch October 7, 2025 11:40
@github-actions github-actions bot mentioned this pull request Oct 7, 2025
@SLAN14
Copy link

SLAN14 commented Oct 7, 2025

Hey @Rich-Harris, this PR is causing issues while building in svelte v4
image

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.

3 participants