@@ -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' ;
@@ -199,7 +199,9 @@ export function proxy(value) {
199199 // internals) that the algorithm reads.
200200 if ( is_proxied_array && typeof prop === 'string' && MUTATING_ARRAY_METHODS . has ( prop ) ) {
201201 /** @type {Map<string, Function> } */
202- const mutating_methods_cache = /** @type {Map<string, Function> } */ ( proxied_array_mutating_methods_cache ) ;
202+ const mutating_methods_cache = /** @type {Map<string, Function> } */ (
203+ proxied_array_mutating_methods_cache
204+ ) ;
203205
204206 var cached_method = mutating_methods_cache . get ( prop ) ;
205207
@@ -212,8 +214,17 @@ export function proxy(value) {
212214 */
213215 cached_method = function ( ...args ) {
214216 // preserve correct `this` binding and forward result.
215- // eslint-disable-next-line prefer-spread
216- return untrack ( ( ) => /** @type {any } */ ( array_prototype ) [ prop ] . apply ( this , args ) ) ;
217+ const fn = /** @type {any } */ ( array_prototype ) [ prop ] ;
218+
219+ // if we are inside a template expression/derived or block effect,
220+ // keep tracking so the runtime can still detect unsafe mutations.
221+ if ( active_reaction !== null && ( active_reaction . f & ( DERIVED | BLOCK_EFFECT ) ) !== 0 ) {
222+ return fn . apply ( this , args ) ;
223+ }
224+
225+ // otherwise (ordinary user effect etc.) suppress dependency tracking
226+ // so we avoid the self-invalidating loop.
227+ return untrack ( ( ) => fn . apply ( this , args ) ) ;
217228 } ;
218229
219230 // give the wrapper a meaningful name for better debugging
0 commit comments