mirror of https://github.com/sveltejs/svelte
fix: spread attributes reactivity improvements (#10071)
- the objects could contain getters with reactive values, so we play it safe and assume they're always reactive - fixes #10065 - isolate spreads with call expression similar to how we do it with other effects -fixes #10013pull/10076/head
parent
877ff1ee7d
commit
570884eabd
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: always treat spread attributes as reactive and separate them if needed
|
@ -0,0 +1,62 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
html: `
|
||||||
|
<button class="red">red</button>
|
||||||
|
<button class="red">red</button>
|
||||||
|
<button class="red">red</button>
|
||||||
|
<button class="red">red</button>
|
||||||
|
`,
|
||||||
|
|
||||||
|
async test({ assert, target }) {
|
||||||
|
const [b1, b2, b3, b4] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
b1?.click();
|
||||||
|
await Promise.resolve();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button class="blue">blue</button>
|
||||||
|
<button class="red">red</button>
|
||||||
|
<button class="red">red</button>
|
||||||
|
<button class="red">red</button>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
b2?.click();
|
||||||
|
await Promise.resolve();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button class="blue">blue</button>
|
||||||
|
<button class="blue">blue</button>
|
||||||
|
<button class="red">red</button>
|
||||||
|
<button class="red">red</button>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
b3?.click();
|
||||||
|
await Promise.resolve();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button class="blue">blue</button>
|
||||||
|
<button class="blue">blue</button>
|
||||||
|
<button class="blue">blue</button>
|
||||||
|
<button class="red">red</button>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
b4?.click();
|
||||||
|
await Promise.resolve();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button class="blue">blue</button>
|
||||||
|
<button class="blue">blue</button>
|
||||||
|
<button class="blue">blue</button>
|
||||||
|
<button class="blue">blue</button>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,24 @@
|
|||||||
|
<script>
|
||||||
|
let tag = $state('button');
|
||||||
|
let values = $state({ a: 'red', b: 'red', c: 'red', d: 'red' });
|
||||||
|
|
||||||
|
let count = 0;
|
||||||
|
const factory = (name) => {
|
||||||
|
count++;
|
||||||
|
// check that spread effects are isolated from each other
|
||||||
|
if (count > 8) throw new Error('too many calls');
|
||||||
|
|
||||||
|
return {
|
||||||
|
class: values[name],
|
||||||
|
onclick: () => {
|
||||||
|
values[name] = 'blue';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button {...factory('a')}>{values.a}</button>
|
||||||
|
<button {...factory('b')}>{values.b}</button>
|
||||||
|
|
||||||
|
<svelte:element this={tag} {...factory('c')}>{values.c}</svelte:element>
|
||||||
|
<svelte:element this={tag} {...factory('d')}>{values.d}</svelte:element>
|
@ -0,0 +1,24 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
html: `
|
||||||
|
<div style="color: red;"></div><div class="red"></div><div class="red"></div>
|
||||||
|
<div style="color: red;"></div><div class="red"></div><div class="red"></div>
|
||||||
|
<button>toggle</button
|
||||||
|
`,
|
||||||
|
|
||||||
|
async test({ assert, target }) {
|
||||||
|
const [b1] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
b1?.click();
|
||||||
|
await Promise.resolve();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<div class="blue" style="color: blue;"></div><div class="blue"></div><div class="blue"></div>
|
||||||
|
<div class="blue" style="color: blue;"></div><div class="blue"></div><div class="blue"></div>
|
||||||
|
<button>toggle</button
|
||||||
|
`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
@ -1,16 +0,0 @@
|
|||||||
import { test } from '../../test';
|
|
||||||
|
|
||||||
export default test({
|
|
||||||
html: `<div style="color: red;"></div><div class="red"></div><button>toggle</button`,
|
|
||||||
|
|
||||||
async test({ assert, target }) {
|
|
||||||
const [b1] = target.querySelectorAll('button');
|
|
||||||
|
|
||||||
b1?.click();
|
|
||||||
await Promise.resolve();
|
|
||||||
assert.htmlEqual(
|
|
||||||
target.innerHTML,
|
|
||||||
'<div class="blue" style="color: blue;"></div><div class="blue"></div><button>toggle</button>'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
Loading…
Reference in new issue