Skip to content

Commit 22fd83b

Browse files
committed
fixup force schedule already executed equal chore
1 parent 64eb10e commit 22fd83b

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

Diff for: packages/qwik/src/core/shared/scheduler.ts

+15-13
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ import { serializeAttribute } from './utils/styles';
113113
import type { ValueOrPromise } from './utils/types';
114114

115115
// Turn this on to get debug output of what the scheduler is doing.
116-
const DEBUG: boolean = true;
116+
const DEBUG: boolean = false;
117117

118118
export const enum ChoreType {
119119
/// MASKS defining three levels of sorting
@@ -547,6 +547,7 @@ export const createScheduler = (
547547
if (isPromise(returnValue)) {
548548
chore.$promise$ = returnValue.then(after, (error) => after(undefined, error));
549549
chore.$resolve$?.(chore.$promise$);
550+
chore.$resolve$ = undefined;
550551
} else {
551552
after(returnValue);
552553
}
@@ -644,28 +645,29 @@ export const createScheduler = (
644645
return ~bottom;
645646
}
646647

647-
/**
648-
* When a derived signal is update we need to run vnode_diff. However the signal can update
649-
* multiple times during component execution. For this reason it is necessary for us to update the
650-
* schedule work with the latest result of the signal.
651-
*/
652-
function choreUpdate(existing: Chore, newChore: Chore): void {
653-
if (existing.$type$ === ChoreType.NODE_DIFF) {
654-
existing.$payload$ = newChore.$payload$;
655-
}
656-
}
657-
658648
function sortedInsert(sortedArray: Chore[], value: Chore, rootVNode: ElementVNode | null): Chore {
659649
/// We need to ensure that the `queue` is sorted by priority.
660650
/// 1. Find a place where to insert into.
661651
const idx = sortedFindIndex(sortedArray, value, rootVNode);
652+
662653
if (idx < 0) {
663654
/// 2. Insert the chore into the queue.
664655
sortedArray.splice(~idx, 0, value);
665656
return value;
666657
}
658+
667659
const existing = sortedArray[idx];
668-
choreUpdate(existing, value);
660+
/**
661+
* When a derived signal is updated we need to run vnode_diff. However the signal can update
662+
* multiple times during component execution. For this reason it is necessary for us to update
663+
* the chore with the latest result of the signal.
664+
*/
665+
if (existing.$type$ === ChoreType.NODE_DIFF) {
666+
existing.$payload$ = value.$payload$;
667+
}
668+
if (existing.$executed$) {
669+
existing.$executed$ = false;
670+
}
669671
return existing;
670672
}
671673
};

Diff for: packages/qwik/src/core/tests/use-task.spec.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import { ErrorProvider } from '../../testing/rendering.unit-util';
1414
import { delay } from '../shared/utils/promises';
1515
import { WrappedSignal } from '../signal/signal';
1616

17-
const debug = !false; //true;
17+
const debug = false; //true;
1818
Error.stackTraceLimit = 100;
1919

2020
describe.each([
2121
{ render: ssrRenderToDom }, //
22-
// { render: domRender }, //
22+
{ render: domRender }, //
2323
])('$render.name: useTask', ({ render }) => {
2424
it('should execute task', async () => {
2525
const Counter = component$(() => {
@@ -759,7 +759,8 @@ describe.each([
759759
);
760760
});
761761
});
762-
it.only('should rerender component after task', async ({}) => {
762+
763+
it('should rerender component after task', async () => {
763764
const Cmp = component$(() => {
764765
const sort = useSignal<'id' | 'size'>('size');
765766
const table = useSignal([

0 commit comments

Comments
 (0)