Skip to content

Commit b6eebcd

Browse files
committed
fix: adding blocking chore multiple times
1 parent 7d809e7 commit b6eebcd

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

packages/qwik/src/core/shared/scheduler-rules.unit.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -969,13 +969,30 @@ describe('addBlockedChore', () => {
969969
const blockedChore1 = createMockChore(ChoreType.VISIBLE, { el: 'host1' });
970970
const blockedChore2 = createMockChore(ChoreType.TASK, { el: 'host2' });
971971
const blockingChore = createMockChore(ChoreType.NODE_DIFF, { el: 'host3' });
972-
blockingChore.$blockedChores$ = [blockedChore1];
972+
blockingChore.$blockedChores$ = new ChoreArray();
973+
blockingChore.$blockedChores$.add(blockedChore1);
973974
const blockedChores = new Set<Chore>([blockedChore1]);
974975

975976
addBlockedChore(blockedChore2, blockingChore, blockedChores);
976977

977-
expect(blockingChore.$blockedChores$).toEqual([blockedChore1, blockedChore2]);
978+
expect(blockingChore.$blockedChores$).toEqual([blockedChore2, blockedChore1]);
978979
expect(blockedChores.has(blockedChore1)).toBe(true);
979980
expect(blockedChores.has(blockedChore2)).toBe(true);
980981
});
982+
983+
it('should not add duplicate blocked chores', () => {
984+
const blockedChore = createMockChore(ChoreType.VISIBLE, { el: 'host1' });
985+
const blockingChore = createMockChore(ChoreType.NODE_DIFF, { el: 'host2' });
986+
const blockedChores = new Set<Chore>();
987+
988+
// Add the same blocked chore twice
989+
addBlockedChore(blockedChore, blockingChore, blockedChores);
990+
addBlockedChore(blockedChore, blockingChore, blockedChores);
991+
992+
// Should only contain the chore once
993+
expect(blockingChore.$blockedChores$).toEqual([blockedChore]);
994+
expect(blockingChore.$blockedChores$?.length).toBe(1);
995+
expect(blockedChores.has(blockedChore)).toBe(true);
996+
expect(blockedChores.size).toBe(1);
997+
});
981998
});

packages/qwik/src/core/shared/scheduler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export interface Chore<T extends ChoreType = ChoreType> {
154154
$target$: ChoreTarget | null;
155155
$payload$: unknown;
156156
$state$: ChoreState;
157-
$blockedChores$: Chore[] | null;
157+
$blockedChores$: ChoreArray | null;
158158
$startTime$: number | undefined;
159159
$endTime$: number | undefined;
160160

@@ -782,8 +782,8 @@ export function addBlockedChore(
782782
undefined,
783783
blockedChores
784784
);
785-
blockingChore.$blockedChores$ ||= [];
786-
blockingChore.$blockedChores$.push(blockedChore);
785+
blockingChore.$blockedChores$ ||= new ChoreArray();
786+
blockingChore.$blockedChores$.add(blockedChore);
787787
blockedChores.add(blockedChore);
788788
if (vnode_isVNode(blockedChore.$host$)) {
789789
(blockedChore.$host$.blockedChores ||= new ChoreArray()).add(blockedChore);

0 commit comments

Comments
 (0)