Skip to content

Commit 64eb10e

Browse files
committed
wip failing component rerender after signal
1 parent 3f0f2a3 commit 64eb10e

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

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

+16-5
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 = false;
116+
const DEBUG: boolean = true;
117117

118118
export const enum ChoreType {
119119
/// MASKS defining three levels of sorting
@@ -259,6 +259,13 @@ export const createScheduler = (
259259
type === ChoreType.NODE_DIFF ||
260260
type === ChoreType.NODE_PROP;
261261
if (isServer && isClientOnly) {
262+
DEBUG &&
263+
debugTrace(
264+
`skip client chore ${debugChoreTypeToString(type)}`,
265+
null,
266+
currentChore,
267+
choreQueue
268+
);
262269
return;
263270
}
264271

@@ -675,8 +682,8 @@ function vNodeAlreadyDeleted(chore: Chore): boolean {
675682
);
676683
}
677684

678-
function debugChoreToString(chore: Chore): string {
679-
const type =
685+
function debugChoreTypeToString(type: ChoreType): string {
686+
return (
680687
(
681688
{
682689
[ChoreType.QRL_RESOLVE]: 'QRL_RESOLVE',
@@ -691,8 +698,12 @@ function debugChoreToString(chore: Chore): string {
691698
[ChoreType.VISIBLE]: 'VISIBLE',
692699
[ChoreType.CLEANUP_VISIBLE]: 'CLEANUP_VISIBLE',
693700
[ChoreType.WAIT_FOR_ALL]: 'WAIT_FOR_ALL',
694-
} as any
695-
)[chore.$type$] || 'UNKNOWN: ' + chore.$type$;
701+
} as Record<ChoreType, string>
702+
)[type] || 'UNKNOWN: ' + type
703+
);
704+
}
705+
function debugChoreToString(chore: Chore): string {
706+
const type = debugChoreTypeToString(chore.$type$);
696707
const host = String(chore.$host$).replaceAll(/\n.*/gim, '');
697708
const qrlTarget = (chore.$target$ as QRLInternal<any>)?.$symbol$;
698709
return `Chore(${type} ${chore.$type$ === ChoreType.QRL_RESOLVE || chore.$type$ === ChoreType.RUN_QRL ? qrlTarget : host} ${chore.$idx$})`;

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

+25-2
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,4 +759,27 @@ describe.each([
759759
);
760760
});
761761
});
762+
it.only('should rerender component after task', async ({}) => {
763+
const Cmp = component$(() => {
764+
const sort = useSignal<'id' | 'size'>('size');
765+
const table = useSignal([
766+
{ id: 1, size: 4 },
767+
{ id: 2, size: 3 },
768+
{ id: 3, size: 2 },
769+
{ id: 4, size: 1 },
770+
{ id: 5, size: 7 },
771+
{ id: 6, size: 8 },
772+
{ id: 7, size: 9 },
773+
]);
774+
775+
useTask$(({ track }) => {
776+
track(() => sort.value);
777+
table.value = table.value.sort((a, b) => a[sort.value] - b[sort.value]).slice();
778+
});
779+
780+
return table.value.map((row) => row.size).join(' ');
781+
});
782+
const { vNode } = await render(<Cmp />, { debug });
783+
expect(vNode).toMatchVDOM(<Component>1 2 3 4 7 8 9</Component>);
784+
});
762785
});

0 commit comments

Comments
 (0)