Skip to content

fix: better update proxy version #10614

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
22 changes: 13 additions & 9 deletions packages/svelte/src/internal/client/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { DEV } from 'esm-env';
import {
get,
set,
update,
updating_derived,
batch_inspect,
current_component_context,
set_ignore_mutation_validation,
untrack
untrack,
set_signal_value
} from './runtime.js';
import { effect_active } from './reactivity/computations.js';
import {
Expand Down Expand Up @@ -150,6 +149,15 @@ export function unstate(value) {
);
}

/**
* @param {import('./types.js').Signal<number>} signal
* @param {1 | -1} [d]
*/
function update_version(signal, d = 1) {
const value = untrack(() => get(signal));
set_signal_value(signal, value + d);
}

/** @type {ProxyHandler<import('./types.js').ProxyStateObject<any>>} */
const state_proxy_handler = {
defineProperty(target, prop, descriptor) {
Expand Down Expand Up @@ -185,9 +193,7 @@ const state_proxy_handler = {
if (s !== undefined) set(s, UNINITIALIZED);

if (boolean) {
set_ignore_mutation_validation(true);
update(metadata.v);
set_ignore_mutation_validation(false);
update_version(metadata.v);
}

return boolean;
Expand Down Expand Up @@ -308,9 +314,7 @@ const state_proxy_handler = {
set(ls, length);
}
}
set_ignore_mutation_validation(true);
update(metadata.v);
set_ignore_mutation_validation(false);
update_version(metadata.v);
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/src/internal/client/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,7 @@ export function inspect(get_value, inspect = console.log) {

pre_effect(() => {
const fn = () => {
const value = get_value().map((v) => deep_unstate(v));
const value = untrack(() => get_value().map((v) => deep_unstate(v)));
if (value.length === 2 && typeof value[1] === 'function' && !warned_inspect_changed) {
// eslint-disable-next-line no-console
console.warn(
Expand Down