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/poor-peaches-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@qwik.dev/core': patch
---

fix: correct running chores handling edge case
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('should block journal flush during node-diff and component runs', () =>
let vA: ElementVNode = null!;
let vAHost: VirtualVNode = null!;
let choreQueue: ChoreArray;
let blockedChores: Set<Chore>;
let blockedChores: ChoreArray;
let runningChores: Set<Chore>;

async function waitForDrain() {
Expand All @@ -44,7 +44,7 @@ describe('should block journal flush during node-diff and component runs', () =>
const container = getDomContainer(document.body);
container.handleError = vi.fn();
choreQueue = new ChoreArray();
blockedChores = new Set();
blockedChores = new ChoreArray();
runningChores = new Set();
scheduler = createScheduler(
container,
Expand Down
31 changes: 24 additions & 7 deletions packages/qwik/src/core/shared/scheduler-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from '../client/vnode';
import { Task, TaskFlags } from '../use/use-task';
import type { QRLInternal } from './qrl/qrl-class';
import type { Chore } from './scheduler';
import { ChoreState, type Chore } from './scheduler';
import type { Container, HostElement } from './types';
import { ChoreType } from './util-chore-type';
import { ELEMENT_SEQ } from './utils/markers';
Expand Down Expand Up @@ -147,7 +147,8 @@ function findAncestorBlockingChore(chore: Chore, type: ChoreSetType): Chore | nu
blockingChore.$type$ < ChoreType.VISIBLE &&
blockingChore.$type$ !== ChoreType.TASK &&
blockingChore.$type$ !== ChoreType.QRL_RESOLVE &&
blockingChore.$type$ !== ChoreType.RUN_QRL
blockingChore.$type$ !== ChoreType.RUN_QRL &&
blockingChore.$state$ === ChoreState.NONE
) {
return blockingChore;
}
Expand All @@ -161,7 +162,7 @@ function findAncestorBlockingChore(chore: Chore, type: ChoreSetType): Chore | nu
export function findBlockingChore(
chore: Chore,
choreQueue: ChoreArray,
blockedChores: Set<Chore>,
blockedChores: ChoreArray,
runningChores: Set<Chore>,
container: Container
): Chore | null {
Expand All @@ -185,20 +186,32 @@ export function findBlockingChore(
// Check in choreQueue
// TODO(perf): better to iterate in reverse order?
for (const candidate of choreQueue) {
if (candidate.$type$ === rule.blockingType && rule.match(chore, candidate, container)) {
if (
candidate.$type$ === rule.blockingType &&
rule.match(chore, candidate, container) &&
candidate.$state$ === ChoreState.NONE
) {
return candidate;
}
}
// Check in blockedChores
for (const candidate of blockedChores) {
if (candidate.$type$ === rule.blockingType && rule.match(chore, candidate, container)) {
if (
candidate.$type$ === rule.blockingType &&
rule.match(chore, candidate, container) &&
candidate.$state$ === ChoreState.NONE
) {
return candidate;
}
}

// Check in runningChores
for (const candidate of runningChores) {
if (candidate.$type$ === rule.blockingType && rule.match(chore, candidate, container)) {
if (
candidate.$type$ === rule.blockingType &&
rule.match(chore, candidate, container) &&
candidate.$state$ !== ChoreState.FAILED
) {
return candidate;
}
}
Expand Down Expand Up @@ -236,7 +249,11 @@ export function findBlockingChoreForVisible(
}

for (const candidate of runningChores) {
if (candidate.$type$ === rule.blockingType && rule.match(chore, candidate, container)) {
if (
candidate.$type$ === rule.blockingType &&
rule.match(chore, candidate, container) &&
candidate.$state$ !== ChoreState.FAILED
) {
return candidate;
}
}
Expand Down
Loading
Loading