fix: improve proxy effect dependency tracking (#10605)

pull/10608/head
Dominic Gannaway 10 months ago committed by GitHub
parent 6afaf75a37
commit c10337cfb2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: improve proxy effect dependency tracking

@ -5,7 +5,8 @@ import {
update, update,
updating_derived, updating_derived,
batch_inspect, batch_inspect,
current_component_context current_component_context,
set_ignore_mutation_validation
} from './runtime.js'; } from './runtime.js';
import { effect_active } from './reactivity/computations.js'; import { effect_active } from './reactivity/computations.js';
import { import {
@ -182,7 +183,11 @@ const state_proxy_handler = {
} }
if (s !== undefined) set(s, UNINITIALIZED); if (s !== undefined) set(s, UNINITIALIZED);
if (boolean) update(metadata.v); if (boolean) {
set_ignore_mutation_validation(true);
update(metadata.v);
set_ignore_mutation_validation(false);
}
return boolean; return boolean;
}, },
@ -291,8 +296,9 @@ const state_proxy_handler = {
set(ls, length); set(ls, length);
} }
} }
set_ignore_mutation_validation(true);
update(metadata.v); update(metadata.v);
set_ignore_mutation_validation(false);
} }
return true; return true;

@ -0,0 +1,12 @@
<script>
import { getContext } from 'svelte';
let context = getContext('container');
$effect(() => {
context.register('test');
return () => context.unregister('test');
});
</script>
<div>Item</div>

@ -0,0 +1,9 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
test({ assert, target }) {
flushSync();
assert.htmlEqual(target.innerHTML, `<div>Item</div>`);
}
});

@ -0,0 +1,14 @@
<script>
import { setContext } from 'svelte';
import Item from './Item.svelte'
let items = $state({});
setContext('container', {
register: (id) => items[id] = true,
unregister: (id) => delete items[id]
});
</script>
<Item />
Loading…
Cancel
Save