@@ -10,7 +10,7 @@ import {
10
10
define_property
11
11
} from '../shared/utils.js' ;
12
12
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' ;
14
14
import { UNINITIALIZED } from '../../constants.js' ;
15
15
import * as e from './errors.js' ;
16
16
import { get_stack , tag } from './dev/tracing.js' ;
@@ -199,7 +199,9 @@ export function proxy(value) {
199
199
// internals) that the algorithm reads.
200
200
if ( is_proxied_array && typeof prop === 'string' && MUTATING_ARRAY_METHODS . has ( prop ) ) {
201
201
/** @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
+ ) ;
203
205
204
206
var cached_method = mutating_methods_cache . get ( prop ) ;
205
207
@@ -212,8 +214,17 @@ export function proxy(value) {
212
214
*/
213
215
cached_method = function ( ...args ) {
214
216
// 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 ) ) ;
217
228
} ;
218
229
219
230
// give the wrapper a meaningful name for better debugging
0 commit comments