-
-
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
class:directive not working with $$restProps
#15386
Comments
My bads :/ I think I found the problem here : svelte/packages/svelte/src/internal/client/dom/elements/attributes.js Lines 380 to 383 in 3d59e84
The directives are not copied to the current state, so falsy value are not correctly updated :( This should solve the problem : } else if (key === 'class') {
var is_html = element.namespaceURI === 'http://www.w3.org/1999/xhtml';
set_class(element, is_html, value, css_hash, prev?.[CLASS], next[CLASS]);
+ current[CLASS] = next[CLASS];
} else if (key === 'style' && value != null) { And it would be better to do an additional check in svelte/packages/svelte/src/internal/client/dom/elements/class.js Lines 36 to 45 in 3d59e84
} else if (next_classes) {
- prev_classes ??= {};
+ var force_update = prev_classes == null;
for (var key in next_classes) {
var is_present = !!next_classes[key];
if (force_update || is_present !== !!prev_classes[key]) {
dom.classList.toggle(key, is_present);
}
} I cannot make a PR for now, so if anyone can do it... |
I’m seeing the same problem with runes mode enabled. Source |
Yes the bug was introduced in the It's fixed on the PR in legacy mode or runes mode |
* add spread to test * fix #15386 * do no set cssHash on non-scoped element * changeset
Describe the bug
I'm experiencing this bug with Svelte versions 5.20.3 and 5.20.4.
If I have a component that uses a
class:
directive to toggle a class and also spread$$restProps
to it, theclass:
directive is not updated.In the provided repro, do the following:
active
prop passed to the Component should turn it blue{active}
updates in the slot, but the class directive is not updatedNow remove the
$$restProps
from the Component; it works as expected. The expected behavior is that theclass:
directive should still re-compute with$$restProps
being spread.From what I can tell, this was working with early patches of 5.20.
Based on the changelog of 5.20.3, I wonder if this could be related to the issue?
fix: correctly override class attributes with class directives
For additional context, I stumbled upon this when investigating this issue for Carbon Svelte: carbon-design-system/carbon-components-svelte#2102
Reproduction
https://svelte.dev/playground/e7cf33de70ae4059a5c99bb3b6c8fefa?version=5.20.4
Logs
System Info
Severity
blocking an upgrade
The text was updated successfully, but these errors were encountered: