Skip to content
Closed
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/fix-latest-loading-lane.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solidjs/signals": patch
---

Keep `latest()` render readers independent from async Loading optimistic lanes so repeated refreshes are not held until unrelated async work settles.
1 change: 0 additions & 1 deletion packages/signals/src/core/lanes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export function getOrCreateLane(signal: Signal<any>): OptimisticLane {
// the owner's write merges the companion's subscribers into this lane and
// their effects wait on its async instead of flushing immediately.
adoptCompanionLane(signal._x?._pendingSignal, lane);
adoptCompanionLane(signal._x?._latestValueComputed, lane);
return lane;
}

Expand Down
48 changes: 48 additions & 0 deletions packages/signals/tests/latest-async.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
import {
createMemo,
createLoadingBoundary,
createRenderEffect,
createRoot,
createSignal,
Expand Down Expand Up @@ -51,6 +52,7 @@ it("latest(asyncMemo) settles to the resolved value and re-reports pending on ea
await current.promise;
return `AV${c}`;
});

createRenderEffect(
() => latest(asyncValue),
v => {
Expand Down Expand Up @@ -99,3 +101,49 @@ it("latest(asyncMemo) settles to the resolved value and re-reports pending on ea
expect(latestLog.at(-1)).toBe("AV2");
expect(pendingLog.at(-1)).toBe(false);
});

it("latest render readers update while unrelated Loading work is pending (#3289)", async () => {
const [reload, setReload] = createSignal(0);
const gates = [deferred<void>(), deferred<void>(), deferred<void>()];
const tabValues: number[] = [];

createRoot(() => {
const graphs = gates.map((gate, index) =>
createMemo(async () => {
latest(reload);
await gate.promise;
return index;
})
);

const boundary = createLoadingBoundary(
() => graphs.map(graph => [isPending(() => graph()), graph()]),
() => "loading"
);

createRenderEffect(
() => boundary(),
() => {}
);

createRenderEffect(
() => latest(reload),
value => {
tabValues.push(value);
}
);
});

flush();
expect(tabValues).toEqual([0]);

for (let value = 1; value <= 3; value++) {
setReload(value);
flush();
expect(tabValues.at(-1)).toBe(value);
}

gates.forEach(gate => gate.resolve());
await settle();
expect(tabValues.at(-1)).toBe(3);
});
Loading