From 400ba719b50530e3fc08a7867568c97d4d63fa47 Mon Sep 17 00:00:00 2001 From: Laurin Weger Date: Fri, 29 Aug 2025 12:32:31 +0200 Subject: [PATCH] fix array modification --- README.md | 1 + src/deepSignal.ts | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7a2ce4f..04d87db 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ Core idea: wrap a data tree in a `Proxy` that lazily creates per-property signal * Lazy: signals & child proxies created only when touched. * Deep: nested objects, arrays, Sets proxied on demand. + * [ ] TODO: Methods might not be proxied (e.g. array.push)? * Per-property signals: fine‑grained invalidation without traversal on each change. * Patch stream: microtask‑batched granular mutations (paths + op) for syncing external stores / framework adapters. * Getter => computed: property getters become derived (readonly) signals automatically. diff --git a/src/deepSignal.ts b/src/deepSignal.ts index 231fdde..f70a396 100644 --- a/src/deepSignal.ts +++ b/src/deepSignal.ts @@ -644,8 +644,19 @@ const objectHandlers = { if (shouldProxy(val)) { if (!objToProxy.has(val)) { // Link newly wrapped child to its parent for path reconstruction. - const parentMeta = proxyMeta.get(receiver)!; - const childProxy = createProxy(val, objectHandlers, parentMeta.root); + // In some edge cases parent metadata might not yet be initialized (e.g., + // if a proxied structure was reconstructed in a way that bypassed the + // original deepSignal root path). Fall back to creating/assigning it. + let parentMeta = proxyMeta.get(receiver); + if (!parentMeta) { + // Assign a root id (new symbol) so downstream patches remain groupable. + const created: ProxyMeta = { + root: Symbol("deepSignalRootAuto"), + } as ProxyMeta; + proxyMeta.set(receiver, created); + parentMeta = created; + } + const childProxy = createProxy(val, objectHandlers, parentMeta!.root); const childMeta = proxyMeta.get(childProxy)!; childMeta.parent = receiver; childMeta.key = fullKey;