-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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: update value like attributes in a separate template_effect #11720
fix: update value like attributes in a separate template_effect #11720
Conversation
🦋 Changeset detectedLatest commit: 411065b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
It would be good to have a test like the original case and also one where we spread the value in too. |
I think this is the correct fix - the |
The original case is covered by the legacy test but i can add it anyway
Sure...adding it right now |
I think it's fine to not add another test, as you say the legacy test covers it |
I just added the spread test for |
Mmm testing the test for spread in the current playground i see that is still working despite being in a single $.template_effect(() => {
attributes = $.set_attributes(input, attributes, { type: "text", ...value }, true, "");
attributes_1 = $.set_attributes(textarea, attributes_1, { ...value }, true, "");
attributes_2 = $.set_attributes(input_1, attributes_2, { type: "checkbox", ...checked }, true, "");
$.set_text(text, $.get(count));
}); it's not completely clear to me why it is working even if it's updating the attributes again but maybe there's some check in |
@paoloricciuti Ah that could be because are using our internal property cache on the DOM element. I wonder if we can re-use that for values too actually? Instead of having a separate template effect, maybe we can create a function that sets the value and also uses that internal property. I'll have a look into that now. |
Implemented an alternative that avoids needing to make extra effects #11726 |
Uh i wasn't aware of that internal cache...your solution is much better 🎉 |
Svelte 5 rewrite
Closes #11718
template_effects for values that the user can change outside of the reactivity (like
value
orchecked
) needs to be isolated or else an unrelated change could reset the input.Please note that the Svelte codebase is currently being rewritten for Svelte 5. Changes should target Svelte 5, which lives on the default branch (
main
).If your PR concerns Svelte 4 (including updates to svelte.dev.docs), please ensure the base branch is
svelte-4
and notmain
.Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.Tests and linting
pnpm test
and lint the project withpnpm lint