From 0ba35406dc95d68eae379ce3d2161ee4f33052af Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Thu, 6 Nov 2025 20:08:39 +0100 Subject: [PATCH] Correct cached vs non-cached shape --- .changeset/slow-dolphins-wave.md | 6 ++++++ packages/preact/utils/src/index.tsx | 15 ++++++--------- packages/react/utils/src/index.tsx | 23 +++++++---------------- 3 files changed, 19 insertions(+), 25 deletions(-) create mode 100644 .changeset/slow-dolphins-wave.md diff --git a/.changeset/slow-dolphins-wave.md b/.changeset/slow-dolphins-wave.md new file mode 100644 index 000000000..7ded5c8f7 --- /dev/null +++ b/.changeset/slow-dolphins-wave.md @@ -0,0 +1,6 @@ +--- +"@preact/signals-react": patch +"@preact/signals": patch +--- + +Ensure the cached and non-cached shape is the same diff --git a/packages/preact/utils/src/index.tsx b/packages/preact/utils/src/index.tsx index 43654c1c0..01df23cff 100644 --- a/packages/preact/utils/src/index.tsx +++ b/packages/preact/utils/src/index.tsx @@ -10,14 +10,9 @@ interface ShowProps { } const Item = (props: any) => { - const result = - typeof props.children === "function" - ? props.children(props.v, props.i) - : props.children; - if (props.cache) { - props.cache.set(props.v, result); - } - return result; + return typeof props.children === "function" + ? props.children(props.v, props.i) + : props.children; }; export function Show(props: ShowProps): JSX.Element | null { @@ -47,7 +42,9 @@ export function For(props: ForProps): JSX.Element | null { const items = list.map((value, key) => { if (!cache.has(value)) { - return ; + const result = ; + cache.set(value, result); + return result; } return cache.get(value); }); diff --git a/packages/react/utils/src/index.tsx b/packages/react/utils/src/index.tsx index bd3b615c6..24369a1b9 100644 --- a/packages/react/utils/src/index.tsx +++ b/packages/react/utils/src/index.tsx @@ -11,14 +11,9 @@ interface ShowProps { const Item = (props: any) => { useSignals(); - const result = - typeof props.children === "function" - ? props.children(props.v, props.i) - : props.children; - if (props.cache) { - props.cache.set(props.v, result); - } - return result; + return typeof props.children === "function" + ? props.children(props.v, props.i) + : props.children; }; export function Show(props: ShowProps): JSX.Element | null { @@ -50,15 +45,11 @@ export function For(props: ForProps): JSX.Element | null { const items = list.map((value, key) => { if (!cache.has(value)) { - return ( - + const result = ( + ); + cache.set(value, result); + return result; } return cache.get(value); });