Skip to content

fix: improve proxy effect dependency tracking #10605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cold-masks-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte": patch
---

fix: improve proxy effect dependency tracking
12 changes: 9 additions & 3 deletions packages/svelte/src/internal/client/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
update,
updating_derived,
batch_inspect,
current_component_context
current_component_context,
set_ignore_mutation_validation
} from './runtime.js';
import { effect_active } from './reactivity/computations.js';
import {
Expand Down Expand Up @@ -182,7 +183,11 @@ const state_proxy_handler = {
}
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;
},
Expand Down Expand Up @@ -291,8 +296,9 @@ const state_proxy_handler = {
set(ls, length);
}
}

set_ignore_mutation_validation(true);
update(metadata.v);
set_ignore_mutation_validation(false);
}

return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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>`);
}
});
Original file line number Diff line number Diff line change
@@ -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 />