From 25cba4e1308d86b3b600635675457736253e2c5c Mon Sep 17 00:00:00 2001 From: chelproc Date: Sun, 1 Nov 2026 12:07:46 +0900 Subject: [PATCH] Clear the snapshot cache of useComponentPins and useNodePins on store changes --- src/store/react/selectors.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/store/react/selectors.ts b/src/store/react/selectors.ts index 8ab7ac8..c90c73f 100644 --- a/src/store/react/selectors.ts +++ b/src/store/react/selectors.ts @@ -151,7 +151,10 @@ export function useComponentPins(componentId: CCComponentId) { const subscribe = useCallback( (onStoreChange: () => void) => { const handler = (componentPin: CCComponentPin) => { - if (componentPin.componentId === componentId) onStoreChange(); + if (componentPin.componentId === componentId) { + getSnapshot.clear(); + onStoreChange(); + } }; store.componentPins.on("didRegister", handler); store.componentPins.on("didUpdate", handler); @@ -162,7 +165,7 @@ export function useComponentPins(componentId: CCComponentId) { store.componentPins.off("didUnregister", handler); }; }, - [store, componentId], + [getSnapshot, store, componentId], ); return useSyncExternalStore(subscribe, getSnapshot); } @@ -176,7 +179,10 @@ export function useNodePins(nodeId: CCNodeId) { const subscribe = useCallback( (onStoreChange: () => void) => { const handler = (nodePin: CCNodePin) => { - if (nodePin.nodeId === nodeId) onStoreChange(); + if (nodePin.nodeId === nodeId) { + getSnapshot.clear(); + onStoreChange(); + } }; store.nodePins.on("didRegister", handler); store.nodePins.on("didUnregister", handler); @@ -185,7 +191,7 @@ export function useNodePins(nodeId: CCNodeId) { store.nodePins.off("didUnregister", handler); }; }, - [store, nodeId], + [getSnapshot, store, nodeId], ); return useSyncExternalStore(subscribe, getSnapshot); }