@@ -10,7 +10,7 @@ import {
1010 define_property
1111} from '../shared/utils.js' ;
1212import { 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' ;
1414import { UNINITIALIZED } from '../../constants.js' ;
1515import * as e from './errors.js' ;
1616import { 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