Skip to content
Draft
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
7 changes: 7 additions & 0 deletions .changeset/guard-null-vnode-mark-dirty.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@qwik.dev/core': patch
---

fix: guard null/undefined vNode in markVNodeDirty

Prevent `TypeError: Cannot read properties of undefined (reading 'dirty')` crash in `markVNodeDirty` when callers pass an undefined vNode. This happens when `DomContainer.$destroy$()` is called during async qwikloader dispatch — `$getObjectById$` returns `undefined` for all pending deserialization, so `scheduleTask`, `scheduleEffects`, `_hmr`, `_val`, `_chk`, and `_res` all pass undefined vNodes to `markVNodeDirty`.
7 changes: 7 additions & 0 deletions packages/qwik/src/core/shared/vnode/vnode-dirty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ export function markVNodeDirty(
bits: ChoreBits,
cursorRoot: VNode | null = null
): void {
if (!vNode) {
// vNode can be undefined when a container is destroyed during async qwikloader dispatch.
// DomContainer.$destroy$() replaces $getObjectById$ with () => undefined and truncates
// $stateData$, so deserializeCaptures returns [undefined] for pending event handlers.
// This affects scheduleTask, scheduleEffects, _hmr, _val, _chk, and _res.
return;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then its a bug that this funtion called on container destroyed, it is workaround not real fix

const prevDirty = vNode.dirty;
vNode.dirty |= bits;
if (isSsrNodeGuard(vNode)) {
Expand Down
23 changes: 23 additions & 0 deletions packages/qwik/src/core/shared/vnode/vnode-dirty.unit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { describe, expect, it, vi } from 'vitest';
import { markVNodeDirty } from './vnode-dirty';
import { ChoreBits } from './enums/chore-bits.enum';
import type { Container } from '../types';

describe('markVNodeDirty', () => {
it('does not throw when vNode is undefined (destroyed container)', () => {
// After DomContainer.$destroy$(), $getObjectById$ returns undefined for all IDs.
// Callers like scheduleTask, _hmr, _val, _chk pass the deserialized result
// directly to markVNodeDirty — which would be undefined.
const container = {} as Container;
expect(() => {
markVNodeDirty(container, undefined as any, ChoreBits.TASKS);
}).not.toThrow();
});

it('does not throw when vNode is null', () => {
const container = {} as Container;
expect(() => {
markVNodeDirty(container, null as any, ChoreBits.TASKS);
}).not.toThrow();
});
});
Comment on lines +6 to +23
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are testing a fix, not failing test case. If I understand it correctly, to test it correctly you need to test $destroy$ on container