mirror of https://github.com/sveltejs/svelte
Removes the `WAS_MARKED` logic in favor of a simple `Set` heuristic: If `mark_reactions` goes beyond a certain depth or there are many reactions on a certain signal, initialize it, otherwise keep it `null`. Balances the common case of not having many transitive dependencies with the edge case of cyclic dependencies as was seen in #16658 Fixes #18123remove-was-marked
parent
48dc9b40c0
commit
2275accb29
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: remove `WAS_MARKED` flag in favor of `Set`
|
||||
@ -0,0 +1,7 @@
|
||||
<script>
|
||||
import { store } from "./store.svelte.js";
|
||||
|
||||
// This write marks the derived in main.svelte before it has reactions added to it.
|
||||
// This test checks that this does not cause the WAS_MARKED logic to incorrectly skip marking the derived subsequently.
|
||||
store.set("child-init-write", Math.random());
|
||||
</script>
|
||||
@ -0,0 +1,29 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
async test({ assert, target }) {
|
||||
const [show, hide] = target.querySelectorAll('button');
|
||||
|
||||
hide.click();
|
||||
flushSync();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>show</button>
|
||||
<button>hide</button>
|
||||
`
|
||||
);
|
||||
|
||||
show.click();
|
||||
flushSync();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>show</button>
|
||||
<button>hide</button>
|
||||
<div>visible</div>
|
||||
`
|
||||
);
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,14 @@
|
||||
<script>
|
||||
import Child from "./Child.svelte";
|
||||
import { store } from "./store.svelte.js";
|
||||
|
||||
const visible = $derived(store.get("visible"));
|
||||
const visible2 = $derived(visible);
|
||||
</script>
|
||||
|
||||
<button onclick={() => store.set("visible", true)}>show</button>
|
||||
<button onclick={() => store.set("visible", false)}>hide</button>
|
||||
{#if visible2}
|
||||
<Child />
|
||||
<div>visible</div>
|
||||
{/if}
|
||||
@ -0,0 +1,13 @@
|
||||
class RawStore {
|
||||
values = $state.raw({ visible: true });
|
||||
|
||||
get(key) {
|
||||
return this.values[key];
|
||||
}
|
||||
|
||||
set(key, value) {
|
||||
this.values = { ...this.values, [key]: value };
|
||||
}
|
||||
}
|
||||
|
||||
export const store = new RawStore();
|
||||
Loading…
Reference in new issue