mirror of https://github.com/sveltejs/svelte
Merge b6dbf46eb7 into b4d1583ae2
commit
3e571bd518
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
distinct memoizer on style/class directives
|
||||
@ -0,0 +1,38 @@
|
||||
import { flushSync, tick } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
// This test counts mutations on hydration
|
||||
// set_style() should not mutate style on hydration, except if mismatch
|
||||
export default test({
|
||||
mode: ['server', 'hydrate', 'client'],
|
||||
|
||||
ssrHtml: `
|
||||
<button>click</button>
|
||||
<div class="red"></div>
|
||||
`,
|
||||
|
||||
html: `
|
||||
<button>click</button>
|
||||
<div class="red"></div>
|
||||
`,
|
||||
|
||||
async test({ target, assert, logs }) {
|
||||
flushSync();
|
||||
tick();
|
||||
|
||||
assert.deepEqual(logs, ['is_red()']);
|
||||
|
||||
const btn = target.querySelector('button');
|
||||
const div = target.querySelector('div');
|
||||
|
||||
assert.equal(div?.className, 'red');
|
||||
|
||||
btn?.click();
|
||||
|
||||
flushSync();
|
||||
|
||||
assert.equal(div?.className, 'red active');
|
||||
// only one call here
|
||||
assert.deepEqual(logs, ['is_red()']);
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,10 @@
|
||||
<script>
|
||||
function is_red() {
|
||||
console.log("is_red()");
|
||||
return "red";
|
||||
}
|
||||
|
||||
let active = $state(false);
|
||||
</script>
|
||||
<button onclick={() => active = true}>click</button>
|
||||
<div class:red={is_red()} class:active></div>
|
||||
@ -0,0 +1,43 @@
|
||||
import { flushSync, tick } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
// This test counts mutations on hydration
|
||||
// set_style() should not mutate style on hydration, except if mismatch
|
||||
export default test({
|
||||
mode: ['server', 'hydrate', 'client'],
|
||||
|
||||
ssrHtml: `
|
||||
<button>click</button>
|
||||
<div style="background-color: red; font-size: 1em;"></div>
|
||||
`,
|
||||
|
||||
html: `
|
||||
<button>click</button>
|
||||
<div style="background-color: red; font-size: 1em;"></div>
|
||||
`,
|
||||
|
||||
async test({ target, assert, component, logs }) {
|
||||
flushSync();
|
||||
tick();
|
||||
|
||||
assert.deepEqual(logs, ['makeColor()']);
|
||||
|
||||
const btn = target.querySelector('button');
|
||||
const div = target.querySelector('div');
|
||||
|
||||
// Note : we cannot compare HTML because set_style() use dom.style.cssText
|
||||
// which can alter the format of the attribute...
|
||||
|
||||
assert.equal(div?.style.backgroundColor, 'red');
|
||||
assert.equal(div?.style.fontSize, '1em');
|
||||
|
||||
btn?.click();
|
||||
|
||||
flushSync();
|
||||
|
||||
assert.equal(div?.style.backgroundColor, 'red');
|
||||
assert.equal(div?.style.fontSize, '2em');
|
||||
// only one call here
|
||||
assert.deepEqual(logs, ['makeColor()']);
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,10 @@
|
||||
<script>
|
||||
function makeColor() {
|
||||
console.log("makeColor()");
|
||||
return "red";
|
||||
}
|
||||
|
||||
let size = $state('1em');
|
||||
</script>
|
||||
<button onclick={() => size = '2em'}>click</button>
|
||||
<div style:background-color={makeColor()} style:font-size={size}></div>
|
||||
Loading…
Reference in new issue