Skip to content

Commit d10846b

Browse files
committed
fix qrl resolve chore
1 parent ea6ed77 commit d10846b

File tree

4 files changed

+28
-29
lines changed

4 files changed

+28
-29
lines changed

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

+23-25
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ export const createScheduler = (
170170

171171
function schedule(
172172
type: ChoreType.QRL_RESOLVE,
173-
ignore0: null,
174-
ignore1: QRLInternal<any>
173+
ignore: null,
174+
target: QRLInternal<any>
175175
): ValueOrPromise<void>;
176176
function schedule(type: ChoreType.JOURNAL_FLUSH): ValueOrPromise<void>;
177177
function schedule(type: ChoreType.WAIT_FOR_ALL): ValueOrPromise<void>;
@@ -369,7 +369,7 @@ export const createScheduler = (
369369
break;
370370
case ChoreType.QRL_RESOLVE: {
371371
const target = chore.$target$ as QRLInternal<any>;
372-
returnValue = target.resolve();
372+
returnValue = !target.resolved ? target.resolve() : null;
373373
break;
374374
}
375375
}
@@ -417,7 +417,12 @@ function choreComparator(a: Chore, b: Chore, shouldThrowOnHostMismatch: boolean)
417417
if (a.$type$ !== ChoreType.JOURNAL_FLUSH) {
418418
const aHost = a.$host$;
419419
const bHost = b.$host$;
420-
if (aHost !== bHost) {
420+
421+
const aHostIsQrlResolve = a.$type$ === ChoreType.QRL_RESOLVE;
422+
const bHostIsQrlResolve = b.$type$ === ChoreType.QRL_RESOLVE;
423+
424+
// QRL_RESOLVE does not have a host.
425+
if (aHost !== bHost && !aHostIsQrlResolve && !bHostIsQrlResolve) {
421426
if (vnode_isVNode(aHost) && vnode_isVNode(bHost)) {
422427
// we are running on the client.
423428
const hostDiff = vnode_documentPosition(aHost, bHost);
@@ -444,6 +449,18 @@ function choreComparator(a: Chore, b: Chore, shouldThrowOnHostMismatch: boolean)
444449
return microTypeDiff;
445450
}
446451

452+
/**
453+
* QRL_RESOLVE is a special case. It does not have a host nor $idx$. We want to process
454+
* QRL_RESOLVE chores as FIFO, so we need to return 1.
455+
*/
456+
if (
457+
aHostIsQrlResolve &&
458+
bHostIsQrlResolve &&
459+
(a.$target$ as QRLInternal<any>).$symbol$ !== (b.$target$ as QRLInternal<any>).$symbol$
460+
) {
461+
return 1;
462+
}
463+
447464
const idxDiff = toNumber(a.$idx$) - toNumber(b.$idx$);
448465
if (idxDiff !== 0) {
449466
return idxDiff;
@@ -453,26 +470,6 @@ function choreComparator(a: Chore, b: Chore, shouldThrowOnHostMismatch: boolean)
453470
return 0;
454471
}
455472

456-
export const intraHostPredicate = (a: Chore, b: Chore): number => {
457-
const idxDiff = toNumber(a.$idx$) - toNumber(b.$idx$);
458-
if (idxDiff !== 0) {
459-
return idxDiff;
460-
}
461-
const typeDiff = a.$type$ - b.$type$;
462-
if (typeDiff !== 0) {
463-
return typeDiff;
464-
}
465-
if (a.$payload$ !== b.$payload$) {
466-
return 0;
467-
}
468-
if (a.$payload$ instanceof Task && b.$payload$ instanceof Task) {
469-
const aHash = a.$payload$.$qrl$.$hash$;
470-
const bHash = b.$payload$.$qrl$.$hash$;
471-
return aHash === bHash ? 0 : aHash < bHash ? -1 : 1;
472-
}
473-
return 0;
474-
};
475-
476473
function sortedFindIndex(sortedArray: Chore[], value: Chore): number {
477474
/// We need to ensure that the `queue` is sorted by priority.
478475
/// 1. Find a place where to insert into.
@@ -525,7 +522,8 @@ function debugChoreToString(chore: Chore): string {
525522
} as any
526523
)[chore.$type$] || 'UNKNOWN: ' + chore.$type$;
527524
const host = String(chore.$host$).replaceAll(/\n.*/gim, '');
528-
return `Chore(${type} ${host} ${chore.$idx$})`;
525+
const qrlTarget = (chore.$target$ as QRLInternal<any>).$symbol$;
526+
return `Chore(${type} ${chore.$type$ === ChoreType.QRL_RESOLVE ? qrlTarget : host} ${chore.$idx$})`;
529527
}
530528

531529
function debugTrace(

packages/qwik/src/core/v2/signal/v2-signal.ts

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { type QRLInternal } from '../../qrl/qrl-class';
1818
import type { QRL } from '../../qrl/qrl.public';
1919
import { trackSignal2, tryGetInvokeContext } from '../../use/use-core';
2020
import { Task, TaskFlags, isTask } from '../../use/use-task';
21+
import { logError } from '../../util/log';
2122
import { ELEMENT_PROPS, OnRenderProp, QSubscribers } from '../../util/markers';
2223
import { isPromise } from '../../util/promises';
2324
import { qDev } from '../../util/qdev';
@@ -311,6 +312,8 @@ export const triggerEffects = (
311312
try {
312313
signal = effect;
313314
effect.$effects$?.forEach(scheduleEffect);
315+
} catch (e: unknown) {
316+
logError(e);
314317
} finally {
315318
signal = previousSignal;
316319
}

packages/qwik/src/core/v2/tests/use-computed.spec.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ import {
99
useStore,
1010
} from '@builder.io/qwik';
1111
import { describe, expect, it } from 'vitest';
12-
import { trigger } from '../../../testing/element-fixture';
13-
import { domRender, ssrRenderToDom } from '../../../testing/rendering.unit-util';
14-
import '../../../testing/vdom-diff.unit-util';
12+
import { trigger, domRender, ssrRenderToDom } from '@builder.io/qwik/testing';
1513

1614
const debug = false; //true;
1715
Error.stackTraceLimit = 100;

starters/e2e/e2e.computed.e2e.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { test, expect } from "@playwright/test";
22

3-
test.describe("slot", () => {
3+
test.describe("computed", () => {
44
function tests() {
55
test("should implement basic computed values", async ({ page }) => {
66
const result = page.locator(".result");

0 commit comments

Comments
 (0)