Skip to content

Commit 0ba3540

Browse files
committed
Correct cached vs non-cached shape
1 parent 1ac2b12 commit 0ba3540

File tree

3 files changed

+19
-25
lines changed

3 files changed

+19
-25
lines changed

.changeset/slow-dolphins-wave.md

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

packages/preact/utils/src/index.tsx

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

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

2318
export function Show<T = boolean>(props: ShowProps<T>): JSX.Element | null {
@@ -47,7 +42,9 @@ export function For<T>(props: ForProps<T>): JSX.Element | null {
4742

4843
const items = list.map((value, key) => {
4944
if (!cache.has(value)) {
50-
return <Item v={value} i={key} children={props.children} cache={cache} />;
45+
const result = <Item v={value} i={key} children={props.children} />;
46+
cache.set(value, result);
47+
return result;
5148
}
5249
return cache.get(value);
5350
});

packages/react/utils/src/index.tsx

Lines changed: 7 additions & 16 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,15 +45,11 @@ 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 (
54-
<Item
55-
v={value}
56-
key={key}
57-
i={key}
58-
children={props.children}
59-
cache={cache}
60-
/>
48+
const result = (
49+
<Item v={value} key={key} i={key} children={props.children} />
6150
);
51+
cache.set(value, result);
52+
return result;
6253
}
6354
return cache.get(value);
6455
});

0 commit comments

Comments
 (0)