-
-
Notifications
You must be signed in to change notification settings - Fork 4.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
bug: The class: directive don't remove existing className on SSR #15338
Comments
In fact, beyond this bug, I think that the => Currently a code like $.template_effect(() => {
$.set_class(div, $.clsx($.get(className)), 'svelte-12n9c8');
$.toggle_class(div, 'red', $.get(red));
$.toggle_class(div, 'important', $.get(important));
}); With the following states:
So, I think that the Something like this : let classes;
$.template_effect(() => {
classes = $.set_class(div, $.clsx($.get(className)), 'svelte-12n9c8', classes, {
red: $.get(red), important: $.get(important)
});
}); By grouping all the processing, this would allow the class to be updated only once when needed. This should also apply to If needed, I think I can develop a POC of this. |
A single method would also solve the fact that that part of the codebase is a nightmare to touch since it relies on the order of things to be precise sometimes pushing updates in the init phase. But a single method would also mean that for every class toggle we would rerun the logic for all the classes no? |
I think it can handle the two cases.
Will try to make a POC... |
Describe the bug
Hi,
This dummy code :
Should produce something like
<div class=""></div>
(or<div></div>
), because the directive takes precedence over the class attribute.But that not the case on SSR where the generated code is
<div class="red"></div>
, which can cause a flash on hydration.Reproduction
Demo on Sveltelabs (for SSR).
Hit the [RELOAD] button to refresh the page :
https://www.sveltelab.dev/je2q9zussa08osn
Logs
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: