Skip to content

Commit 3b14ef4

Browse files
committed
Correct cached vs non-cached shape
1 parent 1ac2b12 commit 3b14ef4

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

.changeset/slow-dolphins-wave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@preact/signals-react": patch
3+
---
4+
5+
Ensure the cached and non-cached shape is the same

packages/react/utils/src/index.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,9 @@ interface ShowProps<T = boolean> {
1111

1212
const Item = (props: any) => {
1313
useSignals();
14-
const result =
15-
typeof props.children === "function"
16-
? props.children(props.v, props.i)
17-
: props.children;
18-
if (props.cache) {
19-
props.cache.set(props.v, result);
20-
}
21-
return result;
14+
return typeof props.children === "function"
15+
? props.children(props.v, props.i)
16+
: props.children;
2217
};
2318

2419
export function Show<T = boolean>(props: ShowProps<T>): JSX.Element | null {
@@ -50,7 +45,7 @@ export function For<T>(props: ForProps<T>): JSX.Element | null {
5045

5146
const items = list.map((value, key) => {
5247
if (!cache.has(value)) {
53-
return (
48+
const result = (
5449
<Item
5550
v={value}
5651
key={key}
@@ -59,6 +54,8 @@ export function For<T>(props: ForProps<T>): JSX.Element | null {
5954
cache={cache}
6055
/>
6156
);
57+
cache.set(value, result);
58+
return result;
6259
}
6360
return cache.get(value);
6461
});

0 commit comments

Comments
 (0)