Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/witty-crabs-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"solid-js": patch
---

make createSelector transition-aware
3 changes: 2 additions & 1 deletion packages/solid/src/reactive/signal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,8 @@ export function createSelector<T, U = T>(
for (const [key, val] of subs.entries())
if (fn(key, v) !== fn(key, p!)) {
for (const c of val.values()) {
c.state = STALE;
if (Transition && Transition.running) c.tState = STALE;
else c.state = STALE;
if (c.pure) Updates!.push(c);
else Effects!.push(c);
}
Expand Down
34 changes: 33 additions & 1 deletion packages/solid/test/signals.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ import {
useContext,
getOwner,
runWithOwner,
children
children,
startTransition
} from "../src/index.js";
import { getSuspenseContext } from "../src/reactive/signal.js";

import "./MessageChannel";

Expand Down Expand Up @@ -811,6 +813,36 @@ describe("createSelector", () => {
});
});
}));

test("selection made inside a transition", async () => {
// startTransition only creates a real Transition once a SuspenseContext exists
getSuspenseContext();

await createRoot(async () => {
const [s, set] = createSignal<number>(-1),
isSelected = createSelector<number, number>(s);
let count = 0;
const list = Array.from({ length: 3 }, (_, i) =>
createMemo(() => {
count++;
return isSelected(i) ? "selected" : "no";
})
);
expect(count).toBe(3);
expect(list[1]()).toBe("no");

count = 0;
await startTransition(() => set(1));
expect(count).toBe(1);
expect(list[1]()).toBe("selected");

count = 0;
await startTransition(() => set(2));
expect(count).toBe(2);
expect(list[1]()).toBe("no");
expect(list[2]()).toBe("selected");
});
});
});

describe("create and use context", () => {
Expand Down
Loading