Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/slow-dolphins-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@preact/signals-react": patch
"@preact/signals": patch
---

Ensure the cached and non-cached shape is the same
15 changes: 6 additions & 9 deletions packages/preact/utils/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@ interface ShowProps<T = boolean> {
}

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<T = boolean>(props: ShowProps<T>): JSX.Element | null {
Expand Down Expand Up @@ -48,7 +43,9 @@ export function For<T>(props: ForProps<T>): JSX.Element | null {

const items = list.map((value, key) => {
if (!cache.has(value)) {
return <Item v={value} i={key} children={props.children} cache={cache} />;
const result = <Item v={value} i={key} children={props.children} />;
cache.set(value, result);
return result;
}
return cache.get(value);
});
Expand Down
23 changes: 7 additions & 16 deletions packages/react/utils/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,9 @@ interface ShowProps<T = boolean> {

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<T = boolean>(props: ShowProps<T>): JSX.Element | null {
Expand Down Expand Up @@ -51,15 +46,11 @@ export function For<T>(props: ForProps<T>): JSX.Element | null {

const items = list.map((value, key) => {
if (!cache.has(value)) {
return (
<Item
v={value}
key={key}
i={key}
children={props.children}
cache={cache}
/>
const result = (
<Item v={value} key={key} i={key} children={props.children} />
);
cache.set(value, result);
return result;
}
return cache.get(value);
});
Expand Down