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
5 changes: 5 additions & 0 deletions .changeset/fix-scheduler-child-queue-removal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solidjs/signals": patch
---

Keep traversing sibling effect queues when a child queue removes itself or an earlier sibling during a flush. Previously, the shifted sibling could be skipped and leave its queued effects unexecuted.
7 changes: 6 additions & 1 deletion packages/solid-signals/src/core/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,12 @@ export class Queue implements IQueue {
this._queues[type - 1] = [];
runQueue(effects, type);
}
for (let i = 0; i < this._children.length; i++) (this._children[i] as any).run?.(type);
for (let i = 0; i < this._children.length; ) {
const child = this._children[i];
(child as any).run?.(type);
// A child may remove itself or an earlier sibling while its effects run.
if (this._children[i] === child) i++;
}
}
enqueue(type: number, fn: QueueCallback): void {
if (type) {
Expand Down
45 changes: 45 additions & 0 deletions packages/solid-signals/tests/scheduler-livelock.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect, it } from "vitest";
import {
createEffect,
createLoadingBoundary,
createMemo,
createRenderEffect,
createRoot,
Expand Down Expand Up @@ -187,3 +188,47 @@ it("isPending(() => latest(x)) in a user effect does not loop on refetch (#2843)
dispose();
flush();
});

it("disposing the current boundary queue does not skip its sibling", () => {
const effects: string[] = [];
const disposers: (() => void)[] = [];

try {
createRoot(dispose => {
disposers.push(dispose);
createLoadingBoundary(
() => {
createEffect(
() => undefined,
() => {
effects.push("first");
dispose();
}
);
},
() => undefined
)();
});

createRoot(dispose => {
disposers.push(dispose);
createLoadingBoundary(
() => {
createEffect(
() => undefined,
() => {
effects.push("second");
}
);
},
() => undefined
)();
});

flush();
expect(effects).toEqual(["first", "second"]);
} finally {
for (const dispose of disposers) dispose();
flush();
}
});
Loading