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: ensure bound input content is resumed on hydration #11986

Merged
merged 14 commits into from
Jun 11, 2024

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Jun 10, 2024

Fixes #1755.

Before:

Screen.Recording.2024-06-10.at.13.06.17.mov

After:

Screen.Recording.2024-06-10.at.13.05.11.mov

Copy link

changeset-bot bot commented Jun 10, 2024

🦋 Changeset detected

Latest commit: 3fd07ae

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
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

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

Does it make sense / is it possible to apply this logic to other inputs? bind:value for the select and bind:group come to mind.

…t.js

Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
@Rich-Harris
Copy link
Member

Fixes #1755.

image

Finally! I think we probably do need to apply it to other form elements, yeah, if it doesn't already work. I also wonder if we need to fire change/input events in these cases. It might seem odd if bind:value works correctly when hydrating an input but oninput doesn't, especially if you need to refactor from one to the other to implement some validation or whatever.

@trueadm
Copy link
Contributor Author

trueadm commented Jun 10, 2024

I added a test case that shows hydration working correctly :)

Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

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

Test adjustment looks great! Can you add a test for bind:group aswell? And did you look into whether or not it's feasible to handle <select bind:value />?

…t.js

Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
@trueadm
Copy link
Contributor Author

trueadm commented Jun 11, 2024

And did you look into whether or not it's feasible to handle <select bind:value />?

Seems to work already. I didn't need to change anything.

@j
Copy link

j commented Jun 21, 2024

@trueadm I'm seeing a few things.

<script>
  let checked = $state(false);
</script>

<input type="checkbox" bind:checked />

Will reset to initial value on a slow connection. As soon as all JS loads, it'll reset back to being unchecked.

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
4 participants