From 3eea77152f4cb4163c5b5502f0ae525eea697c70 Mon Sep 17 00:00:00 2001 From: David Arenas Date: Wed, 31 Jul 2024 17:02:37 +0200 Subject: [PATCH] Check if length's PropSignal exists before updating its value --- packages/interactivity/src/proxies/state.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/interactivity/src/proxies/state.ts b/packages/interactivity/src/proxies/state.ts index 7b9c0bf4ea09cf..0978fa2ccd0264 100644 --- a/packages/interactivity/src/proxies/state.ts +++ b/packages/interactivity/src/proxies/state.ts @@ -168,7 +168,15 @@ const stateHandlers: ProxyHandler< object > = { objToIterable.get( target )!.value++; } - if ( Array.isArray( target ) ) { + /* + * Modify the `length` property value only if the related + * `PropSignal` exists, which means that there are subscriptions to + * this property. + */ + if ( + Array.isArray( target ) && + proxyToProps.get( receiver )?.has( 'length' ) + ) { const length = getPropSignal( receiver, 'length' ); length.setValue( target.length ); }