mirror of https://github.com/sveltejs/svelte
fix: ensure derived is detected as dirty correctly (#11496)
Deriveds where under certain conditions not detected as dirty correctly. The reason is that a transitive check_dirtiness call could update the flag of a derived, even if the condition doesn't ulimately result to true. That's why the check for "is now dirty" needs to be moved out of the inner if block. Fixes #11481 This may also fix a yet undetected overfiring bug in the "is unowned" case because the previous inner "is now dirty?" check didn't take unowned into account.pull/11474/head
parent
d86b05279f
commit
6bd6f0971b
@ -0,0 +1,5 @@
|
||||
---
|
||||
"svelte": patch
|
||||
---
|
||||
|
||||
fix: ensure derived is detected as dirty correctly
|
@ -0,0 +1,12 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
html: `<button>00</button>`,
|
||||
|
||||
async test({ assert, target }) {
|
||||
const btn = target.querySelector('button');
|
||||
await btn?.click();
|
||||
|
||||
assert.htmlEqual(target.innerHTML, `<button>01</button>`);
|
||||
}
|
||||
});
|
@ -0,0 +1,12 @@
|
||||
<script>
|
||||
let shouldShow01 = $state(false);
|
||||
|
||||
let der1 = $derived(shouldShow01)
|
||||
// der2 must depend on der1 and its output shouldn't change
|
||||
let der2 = $derived(typeof der1 === "string");
|
||||
let der3 = $derived(der2 ? "1" : "0");
|
||||
// der3 must be read before der1
|
||||
let der4 = $derived(der3 + (der1 ? "1" : "0"));
|
||||
</script>
|
||||
|
||||
<button onclick={() => (shouldShow01 = true)}>{der4}</button>
|
Loading…
Reference in new issue