-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Input resets when page fully loads #8266
Comments
This sounds like a timing issue - hydration happens too late, so it clears out the value the user has already typed in. This is not strictly related to SvelteKit, more a general limitation of the current Svelte hydration. |
A decent workaround is to disable the input until hydration has completed: <script lang="ts">
+ import { browser } from '$app/environment';
let a = "234"
</script>
-<input bind:value={a}>
+<input disabled={!browser} bind:value={a}> Ultimately it would be better if the binding was initialized with the input value — not sure if that would cause other problems, but I'd like it if we could do that in a future version of Svelte. |
Yeah, the suggested workaround is good enough for my use-case. It is interesting that |
Transferring to |
Svelte could perhaps check the value of the binding just after hydration ? Something like this approximately : input = claim_element(nodes, "INPUT", {});
// When input is different from the context value
if (input.value !== /*a*/ ctx[0]) {
// We use the binding handler to update it's value
/*input_input_handler*/ ctx[1].call(input).
} |
Probably a duplicate of #1755, which tells you how long this problem has been around. |
Did you have a look into this idea already? I think it would be a good thing to implement because this issue is indeed quite annoying and disabling the input until JS loads also seems like a unnecessary delay. Would be great to have at least the option to enable that via svelte without some hacky workarounds. What do you think? Would love to support you there on that topic, despite svelte code base being new for me :) |
@Rich-Harris Now that we have nice forms that work without JavaScript via |
closing as dupe of #1755 |
Describe the bug
If you load a page which contains an
input
element with value binded to a variable, theinput
will reset all the user edits when page load finishes.I'm not sure if this falls exactly into svelte-kit and will this be considered a bug or not. But it sure is little annoying sometimes.
Reproduction
Repo: https://github.com/nkitsaini/svelte-bug-repro
Video: https://github.com/nkitsaini/svelte-bug-repro/raw/main/repro.mkv
Snippet:
Logs
System Info
Severity
annoyance
Additional Information
No response
The text was updated successfully, but these errors were encountered: