diff --git a/bun.lock b/bun.lock index ecb8dd1b..503c6821 100644 --- a/bun.lock +++ b/bun.lock @@ -342,7 +342,7 @@ }, "packages/csr": { "name": "@wrnexus/csr", - "version": "0.8.32", + "version": "0.8.33", "dependencies": { "@wrnexus/core": "workspace:*", }, diff --git a/packages/csr/package.json b/packages/csr/package.json index 0ed2eba1..bb288d49 100644 --- a/packages/csr/package.json +++ b/packages/csr/package.json @@ -1,6 +1,6 @@ { "name": "@wrnexus/csr", - "version": "0.8.32", + "version": "0.8.33", "type": "module", "main": "src/index.ts", "exports": { diff --git a/packages/csr/src/reactive-runtime.ts b/packages/csr/src/reactive-runtime.ts index f8332f21..47cfd755 100644 --- a/packages/csr/src/reactive-runtime.ts +++ b/packages/csr/src/reactive-runtime.ts @@ -2775,9 +2775,15 @@ export const REACTIVE_RUNTIME = String.raw` // server forwards these markers onto the rendered child root; evaluate // them here and write changes into the child's prop signals. toArray(el.querySelectorAll("*")) - .filter(isScopeRoot) + .filter(function (node) { + return toArray(node.attributes).some(function (attr) { + return attr.name.indexOf("data-wrn-prop-bind-") === 0; + }); + }) .forEach(function (node) { - if (!node.parentNode || ownerScope(node.parentNode) !== el) return; + var targetScope = isScopeRoot(node) ? node : ownerScope(node); + if (!targetScope || targetScope === el) return; + if (!targetScope.parentNode || ownerScope(targetScope.parentNode) !== el) return; toArray(node.attributes).forEach(function (attr) { if (attr.name.indexOf("data-wrn-prop-bind-") !== 0) return; var binding = pairBinding(attr.value); @@ -2796,9 +2802,9 @@ export const REACTIVE_RUNTIME = String.raw` }); } catch (_) { return; } var apply = function () { - if (node.__wrnexusScopeApi) node.__wrnexusScopeApi.set(propName, value); + if (targetScope.__wrnexusScopeApi) targetScope.__wrnexusScopeApi.set(propName, value); }; - if (node.__wrnexusScopeApi) apply(); + if (targetScope.__wrnexusScopeApi) apply(); else queueMicrotask(apply); }); }); diff --git a/packages/csr/test/reactive.test.ts b/packages/csr/test/reactive.test.ts index d8d8fd74..5bce4043 100644 --- a/packages/csr/test/reactive.test.ts +++ b/packages/csr/test/reactive.test.ts @@ -454,6 +454,22 @@ test("parent state updates a mounted child's reactive prop", async () => { expect(win.document.querySelector("#child-value")?.textContent).toBe("2"); }); +test("a prop marker forwarded onto a child control still updates the child scope", async () => { + const win = mount( + `