fix: ensure `undefined` class still applies scoping class, if necessary (#15643)

fixes #15635
pull/15647/head
Simon H 6 months ago committed by GitHub
parent 6f8068637c
commit b93d004d98
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: ensure `undefined` class still applies scoping class, if necessary

@ -14,7 +14,11 @@ export function set_class(dom, is_html, value, hash, prev_classes, next_classes)
// @ts-expect-error need to add __className to patched prototype // @ts-expect-error need to add __className to patched prototype
var prev = dom.__className; var prev = dom.__className;
if (hydrating || prev !== value) { if (
hydrating ||
prev !== value ||
prev === undefined // for edge case of `class={undefined}`
) {
var next_class_name = to_class(value, hash, next_classes); var next_class_name = to_class(value, hash, next_classes);
if (!hydrating || next_class_name !== dom.getAttribute('class')) { if (!hydrating || next_class_name !== dom.getAttribute('class')) {

@ -1 +1,2 @@
<p class="svelte-xyz">Foo</p> <p class="svelte-xyz">Foo</p>
<p class="svelte-xyz">Bar</p>

@ -1,3 +1,4 @@
<style>p { color: red; }</style> <style>p { color: red; }</style>
<p class={undefined}>Foo</p> <p class={undefined}>Foo</p>
<p class="{undefined}">Bar</p>

Loading…
Cancel
Save