Skip to content

Commit b91ce76

Browse files
authored
Merge pull request #8167 from QwikDev/v2-fix-open-code-block
fix(scheduler): handling running chores
2 parents 2e132fc + f026a32 commit b91ce76

File tree

7 files changed

+149
-102
lines changed

7 files changed

+149
-102
lines changed

.changeset/poor-peaches-roll.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@qwik.dev/core': patch
3+
---
4+
5+
fix: correct running chores handling edge case

packages/qwik/src/core/shared/scheduler-journal-block.unit.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('should block journal flush during node-diff and component runs', () =>
3030
let vA: ElementVNode = null!;
3131
let vAHost: VirtualVNode = null!;
3232
let choreQueue: ChoreArray;
33-
let blockedChores: Set<Chore>;
33+
let blockedChores: ChoreArray;
3434
let runningChores: Set<Chore>;
3535

3636
async function waitForDrain() {
@@ -44,7 +44,7 @@ describe('should block journal flush during node-diff and component runs', () =>
4444
const container = getDomContainer(document.body);
4545
container.handleError = vi.fn();
4646
choreQueue = new ChoreArray();
47-
blockedChores = new Set();
47+
blockedChores = new ChoreArray();
4848
runningChores = new Set();
4949
scheduler = createScheduler(
5050
container,

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

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
} from '../client/vnode';
66
import { Task, TaskFlags } from '../use/use-task';
77
import type { QRLInternal } from './qrl/qrl-class';
8-
import type { Chore } from './scheduler';
8+
import { ChoreState, type Chore } from './scheduler';
99
import type { Container, HostElement } from './types';
1010
import { ChoreType } from './util-chore-type';
1111
import { ELEMENT_SEQ } from './utils/markers';
@@ -147,7 +147,8 @@ function findAncestorBlockingChore(chore: Chore, type: ChoreSetType): Chore | nu
147147
blockingChore.$type$ < ChoreType.VISIBLE &&
148148
blockingChore.$type$ !== ChoreType.TASK &&
149149
blockingChore.$type$ !== ChoreType.QRL_RESOLVE &&
150-
blockingChore.$type$ !== ChoreType.RUN_QRL
150+
blockingChore.$type$ !== ChoreType.RUN_QRL &&
151+
blockingChore.$state$ === ChoreState.NONE
151152
) {
152153
return blockingChore;
153154
}
@@ -161,7 +162,7 @@ function findAncestorBlockingChore(chore: Chore, type: ChoreSetType): Chore | nu
161162
export function findBlockingChore(
162163
chore: Chore,
163164
choreQueue: ChoreArray,
164-
blockedChores: Set<Chore>,
165+
blockedChores: ChoreArray,
165166
runningChores: Set<Chore>,
166167
container: Container
167168
): Chore | null {
@@ -185,20 +186,32 @@ export function findBlockingChore(
185186
// Check in choreQueue
186187
// TODO(perf): better to iterate in reverse order?
187188
for (const candidate of choreQueue) {
188-
if (candidate.$type$ === rule.blockingType && rule.match(chore, candidate, container)) {
189+
if (
190+
candidate.$type$ === rule.blockingType &&
191+
rule.match(chore, candidate, container) &&
192+
candidate.$state$ === ChoreState.NONE
193+
) {
189194
return candidate;
190195
}
191196
}
192197
// Check in blockedChores
193198
for (const candidate of blockedChores) {
194-
if (candidate.$type$ === rule.blockingType && rule.match(chore, candidate, container)) {
199+
if (
200+
candidate.$type$ === rule.blockingType &&
201+
rule.match(chore, candidate, container) &&
202+
candidate.$state$ === ChoreState.NONE
203+
) {
195204
return candidate;
196205
}
197206
}
198207

199208
// Check in runningChores
200209
for (const candidate of runningChores) {
201-
if (candidate.$type$ === rule.blockingType && rule.match(chore, candidate, container)) {
210+
if (
211+
candidate.$type$ === rule.blockingType &&
212+
rule.match(chore, candidate, container) &&
213+
candidate.$state$ !== ChoreState.FAILED
214+
) {
202215
return candidate;
203216
}
204217
}
@@ -236,7 +249,11 @@ export function findBlockingChoreForVisible(
236249
}
237250

238251
for (const candidate of runningChores) {
239-
if (candidate.$type$ === rule.blockingType && rule.match(chore, candidate, container)) {
252+
if (
253+
candidate.$type$ === rule.blockingType &&
254+
rule.match(chore, candidate, container) &&
255+
candidate.$state$ !== ChoreState.FAILED
256+
) {
240257
return candidate;
241258
}
242259
}

0 commit comments

Comments
 (0)