Skip to content

Commit 12a0b06

Browse files
committed
Tweak to restore unsafe template mutation tracking
1 parent 50da926 commit 12a0b06

File tree

1 file changed

+16
-2
lines changed
  • packages/svelte/src/internal/client

1 file changed

+16
-2
lines changed

packages/svelte/src/internal/client/proxy.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
define_property
1111
} from '../shared/utils.js';
1212
import { state as source, set } from './reactivity/sources.js';
13-
import { PROXY_PATH_SYMBOL, STATE_SYMBOL } from '#client/constants';
13+
import { PROXY_PATH_SYMBOL, STATE_SYMBOL, DERIVED, BLOCK_EFFECT } from '#client/constants';
1414
import { UNINITIALIZED } from '../../constants.js';
1515
import * as e from './errors.js';
1616
import { get_stack, tag } from './dev/tracing.js';
@@ -212,8 +212,22 @@ export function proxy(value) {
212212
*/
213213
cached_method = function (...args) {
214214
// preserve correct `this` binding and forward result.
215+
const fn = /** @type {any} */ (array_prototype)[prop];
216+
217+
// if we are inside a template expression/derived or block effect,
218+
// keep tracking so the runtime can still detect unsafe mutations.
219+
if (
220+
active_reaction !== null &&
221+
(active_reaction.f & (DERIVED | BLOCK_EFFECT)) !== 0
222+
) {
223+
// eslint-disable-next-line prefer-spread
224+
return fn.apply(this, args);
225+
}
226+
227+
// otherwise (ordinary user effect etc.) suppress dependency tracking
228+
// so we avoid the self-invalidating loop.
215229
// eslint-disable-next-line prefer-spread
216-
return untrack(() => /** @type {any} */ (array_prototype)[prop].apply(this, args));
230+
return untrack(() => fn.apply(this, args));
217231
};
218232

219233
// give the wrapper a meaningful name for better debugging

0 commit comments

Comments
 (0)