From 5f36f0e8653e5584627e037f4ac1211d467bef05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=96=8C?= Date: Tue, 19 Nov 2024 12:17:30 +0800 Subject: [PATCH 1/7] Update store.ts track store modifications in `has()` cases --- packages/qwik/src/core/state/store.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/qwik/src/core/state/store.ts b/packages/qwik/src/core/state/store.ts index e5db4c72bec..a02ed5c4672 100644 --- a/packages/qwik/src/core/state/store.ts +++ b/packages/qwik/src/core/state/store.ts @@ -192,16 +192,24 @@ export class ReadWriteProxyHandler implements ProxyHandler { return true; } - has(target: TargetType, property: string | symbol): boolean { - if (property === QOjectTargetSymbol) { - return true; + has(target, prop) { + if (prop === QOjectTargetSymbol) { + return true; + } + const invokeCtx = tryGetInvokeContext(); + if (invokeCtx) { + const subscriber = invokeCtx.$subscriber$; + if (subscriber) { + const isA = isArray(target); + this.$manager$.$addSub$(subscriber, isA ? undefined : prop); + } } const hasOwnProperty = Object.prototype.hasOwnProperty; - if (hasOwnProperty.call(target, property)) { - return true; + if (hasOwnProperty.call(target, prop)) { + return true; } - if (typeof property === 'string' && hasOwnProperty.call(target, _IMMUTABLE_PREFIX + property)) { - return true; + if (typeof prop === 'string' && hasOwnProperty.call(target, _IMMUTABLE_PREFIX + prop)) { + return true; } return false; } From 7bf14244114125e2eb95c3b82aa0030d0819d3df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=96=8C?= Date: Tue, 19 Nov 2024 12:19:58 +0800 Subject: [PATCH 2/7] Update store.ts amend --- packages/qwik/src/core/state/store.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/qwik/src/core/state/store.ts b/packages/qwik/src/core/state/store.ts index a02ed5c4672..c61cdaf4b5f 100644 --- a/packages/qwik/src/core/state/store.ts +++ b/packages/qwik/src/core/state/store.ts @@ -192,7 +192,7 @@ export class ReadWriteProxyHandler implements ProxyHandler { return true; } - has(target, prop) { + has(target: TargetType, prop: string | symbol): boolean { if (prop === QOjectTargetSymbol) { return true; } From a205c7c3b2bb951d954c56a4f23f241f0c87d26b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=96=8C?= Date: Tue, 19 Nov 2024 12:21:26 +0800 Subject: [PATCH 3/7] Update store.ts format --- packages/qwik/src/core/state/store.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/qwik/src/core/state/store.ts b/packages/qwik/src/core/state/store.ts index c61cdaf4b5f..25e09d03c67 100644 --- a/packages/qwik/src/core/state/store.ts +++ b/packages/qwik/src/core/state/store.ts @@ -194,22 +194,22 @@ export class ReadWriteProxyHandler implements ProxyHandler { has(target: TargetType, prop: string | symbol): boolean { if (prop === QOjectTargetSymbol) { - return true; + return true; } const invokeCtx = tryGetInvokeContext(); if (invokeCtx) { - const subscriber = invokeCtx.$subscriber$; - if (subscriber) { - const isA = isArray(target); - this.$manager$.$addSub$(subscriber, isA ? undefined : prop); - } + const subscriber = invokeCtx.$subscriber$; + if (subscriber) { + const isA = isArray(target); + this.$manager$.$addSub$(subscriber, isA ? undefined : prop); + } } const hasOwnProperty = Object.prototype.hasOwnProperty; if (hasOwnProperty.call(target, prop)) { - return true; + return true; } if (typeof prop === 'string' && hasOwnProperty.call(target, _IMMUTABLE_PREFIX + prop)) { - return true; + return true; } return false; } From e527365c2f3ecb763b68539e8796d1091da1448a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=96=8C?= Date: Tue, 19 Nov 2024 12:36:34 +0800 Subject: [PATCH 4/7] Update store.ts fix compilation --- packages/qwik/src/core/state/store.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/qwik/src/core/state/store.ts b/packages/qwik/src/core/state/store.ts index 25e09d03c67..30fa19fd076 100644 --- a/packages/qwik/src/core/state/store.ts +++ b/packages/qwik/src/core/state/store.ts @@ -199,7 +199,7 @@ export class ReadWriteProxyHandler implements ProxyHandler { const invokeCtx = tryGetInvokeContext(); if (invokeCtx) { const subscriber = invokeCtx.$subscriber$; - if (subscriber) { + if (subscriber && typeof prop === 'string') { const isA = isArray(target); this.$manager$.$addSub$(subscriber, isA ? undefined : prop); } From 63d8b79b0515e5f1497dbce863a5f184921d9a70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=96=8C?= Date: Tue, 19 Nov 2024 15:21:25 +0800 Subject: [PATCH 5/7] Update store.ts prettify --- packages/qwik/src/core/state/store.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/qwik/src/core/state/store.ts b/packages/qwik/src/core/state/store.ts index 30fa19fd076..08d9050740a 100644 --- a/packages/qwik/src/core/state/store.ts +++ b/packages/qwik/src/core/state/store.ts @@ -197,9 +197,9 @@ export class ReadWriteProxyHandler implements ProxyHandler { return true; } const invokeCtx = tryGetInvokeContext(); - if (invokeCtx) { + if (typeof prop === 'string' && invokeCtx) { const subscriber = invokeCtx.$subscriber$; - if (subscriber && typeof prop === 'string') { + if (subscriber) { const isA = isArray(target); this.$manager$.$addSub$(subscriber, isA ? undefined : prop); } From f6422911c99ca4b856c344ace0e3ee77b9091ab2 Mon Sep 17 00:00:00 2001 From: Wout Mertens Date: Wed, 20 Nov 2024 13:14:18 +0100 Subject: [PATCH 6/7] changeset --- .changeset/proud-carrots-grab.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/proud-carrots-grab.md diff --git a/.changeset/proud-carrots-grab.md b/.changeset/proud-carrots-grab.md new file mode 100644 index 00000000000..f632c8c2152 --- /dev/null +++ b/.changeset/proud-carrots-grab.md @@ -0,0 +1,5 @@ +--- +"@builder.io/qwik": patch +--- + +Fix: add subscription when doing `"prop" in store` From 729b82eb91acb021abd4810a6d48ee9b34abbf25 Mon Sep 17 00:00:00 2001 From: Wout Mertens Date: Wed, 20 Nov 2024 13:20:17 +0100 Subject: [PATCH 7/7] prettier --- .changeset/proud-carrots-grab.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/proud-carrots-grab.md b/.changeset/proud-carrots-grab.md index f632c8c2152..8f1f62312b0 100644 --- a/.changeset/proud-carrots-grab.md +++ b/.changeset/proud-carrots-grab.md @@ -1,5 +1,5 @@ --- -"@builder.io/qwik": patch +'@builder.io/qwik': patch --- Fix: add subscription when doing `"prop" in store`