Skip to content

Commit aa1e71a

Browse files
committed
chore: vnode as an object
# Conflicts: # packages/qwik/src/core/shared/shared-serialization.ts # packages/qwik/src/core/shared/types.ts
1 parent 043766c commit aa1e71a

28 files changed

+646
-759
lines changed

packages/docs/src/routes/api/qwik-testing/api.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@
178178
}
179179
],
180180
"kind": "Function",
181-
"content": "```typescript\nexport declare function ssrRenderToDom(jsx: JSXOutput, opts?: {\n debug?: boolean;\n raw?: boolean;\n}): Promise<{\n container: _DomContainer;\n document: Document;\n vNode: _VirtualVNode | null;\n getStyles: () => Record<string, string | string[]>;\n}>;\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\njsx\n\n\n</td><td>\n\nJSXOutput\n\n\n</td><td>\n\n\n</td></tr>\n<tr><td>\n\nopts\n\n\n</td><td>\n\n{ debug?: boolean; raw?: boolean; }\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n</tbody></table>\n\n**Returns:**\n\nPromise&lt;{ container: \\_DomContainer; document: Document; vNode: \\_VirtualVNode \\| null; getStyles: () =&gt; Record&lt;string, string \\| string\\[\\]&gt;; }&gt;",
181+
"content": "```typescript\nexport declare function ssrRenderToDom(jsx: JSXOutput, opts?: {\n debug?: boolean;\n raw?: boolean;\n}): Promise<{\n container: _DomContainer;\n document: Document;\n vNode: _VNode | null;\n getStyles: () => Record<string, string | string[]>;\n}>;\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\njsx\n\n\n</td><td>\n\nJSXOutput\n\n\n</td><td>\n\n\n</td></tr>\n<tr><td>\n\nopts\n\n\n</td><td>\n\n{ debug?: boolean; raw?: boolean; }\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n</tbody></table>\n\n**Returns:**\n\nPromise&lt;{ container: \\_DomContainer; document: Document; vNode: \\_VNode \\| null; getStyles: () =&gt; Record&lt;string, string \\| string\\[\\]&gt;; }&gt;",
182182
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/testing/rendering.unit-util.tsx",
183183
"mdFile": "core.ssrrendertodom.md"
184184
},
@@ -223,7 +223,7 @@
223223
}
224224
],
225225
"kind": "Function",
226-
"content": "```typescript\nexport declare function vnode_fromJSX(jsx: JSXOutput): {\n vParent: _ElementVNode;\n vNode: _VNode | null;\n document: _QDocument;\n container: ClientContainer;\n};\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\njsx\n\n\n</td><td>\n\nJSXOutput\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>\n\n**Returns:**\n\n{ vParent: \\_ElementVNode; vNode: \\_VNode \\| null; document: \\_QDocument; container: ClientContainer; }",
226+
"content": "```typescript\nexport declare function vnode_fromJSX(jsx: JSXOutput): {\n vParent: _ElementVNode | _VirtualVNode;\n vNode: _VNode | null;\n document: _QDocument;\n container: ClientContainer;\n};\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\njsx\n\n\n</td><td>\n\nJSXOutput\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>\n\n**Returns:**\n\n{ vParent: \\_ElementVNode \\| \\_VirtualVNode; vNode: \\_VNode \\| null; document: \\_QDocument; container: ClientContainer; }",
227227
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/testing/vdom-diff.unit-util.ts",
228228
"mdFile": "core.vnode_fromjsx.md"
229229
},

packages/docs/src/routes/api/qwik-testing/index.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ export declare function ssrRenderToDom(
439439
): Promise<{
440440
container: _DomContainer;
441441
document: Document;
442-
vNode: _VirtualVNode | null;
442+
vNode: _VNode | null;
443443
getStyles: () => Record<string, string | string[]>;
444444
}>;
445445
```
@@ -485,7 +485,7 @@ _(Optional)_
485485

486486
**Returns:**
487487

488-
Promise&lt;\{ container: \_DomContainer; document: Document; vNode: \_VirtualVNode \| null; getStyles: () =&gt; Record&lt;string, string \| string[]&gt;; }&gt;
488+
Promise&lt;\{ container: \_DomContainer; document: Document; vNode: \_VNode \| null; getStyles: () =&gt; Record&lt;string, string \| string[]&gt;; }&gt;
489489

490490
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/testing/rendering.unit-util.tsx)
491491

@@ -597,7 +597,7 @@ Promise&lt;void&gt;
597597

598598
```typescript
599599
export declare function vnode_fromJSX(jsx: JSXOutput): {
600-
vParent: _ElementVNode;
600+
vParent: _ElementVNode | _VirtualVNode;
601601
vNode: _VNode | null;
602602
document: _QDocument;
603603
container: ClientContainer;
@@ -632,7 +632,7 @@ JSXOutput
632632

633633
**Returns:**
634634

635-
\{ vParent: \_ElementVNode; vNode: \_VNode \| null; document: \_QDocument; container: ClientContainer; }
635+
\{ vParent: \_ElementVNode \| \_VirtualVNode; vNode: \_VNode \| null; document: \_QDocument; container: ClientContainer; }
636636

637637
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/testing/vdom-diff.unit-util.ts)
638638

packages/qwik/src/core/client/dom-container.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,9 @@ import type { ContextId } from '../use/use-context';
4242
import { processVNodeData } from './process-vnode-data';
4343
import {
4444
VNodeFlags,
45-
VNodeProps,
4645
type ContainerElement,
47-
type ElementVNode,
4846
type ClientContainer as IClientContainer,
4947
type QDocument,
50-
type VNode,
51-
type VirtualVNode,
5248
} from './types';
5349
import { mapArray_get, mapArray_has, mapArray_set } from './util-mapArray';
5450
import {
@@ -58,16 +54,16 @@ import {
5854
vnode_getDomParent,
5955
vnode_getNextSibling,
6056
vnode_getParent,
61-
vnode_getProp,
6257
vnode_getProps,
6358
vnode_insertBefore,
6459
vnode_isElementVNode,
60+
vnode_isVNode,
6561
vnode_isVirtualVNode,
6662
vnode_locate,
6763
vnode_newUnMaterializedElement,
68-
vnode_setProp,
6964
type VNodeJournal,
7065
} from './vnode';
66+
import type { ElementVNode, VirtualVNode, VNode } from './vnode-impl';
7167

7268
/** @public */
7369
export function getDomContainer(element: Element | VNode): IClientContainer {
@@ -89,7 +85,7 @@ export function getDomContainerFromQContainerElement(qContainerElement: Element)
8985

9086
/** @internal */
9187
export function _getQContainerElement(element: Element | VNode): Element | null {
92-
const qContainerElement: Element | null = Array.isArray(element)
88+
const qContainerElement: Element | null = vnode_isVNode(element)
9389
? (vnode_getDomParent(element, true) as Element)
9490
: element;
9591
return qContainerElement.closest(QContainerSelector);
@@ -230,13 +226,13 @@ export class DomContainer extends _SharedContainer implements IClientContainer {
230226
let vNode = vnode_getParent(host as any);
231227
while (vNode) {
232228
if (vnode_isVirtualVNode(vNode)) {
233-
if (vnode_getProp(vNode, OnRenderProp, null) !== null) {
229+
if (vNode.getProp(OnRenderProp, null) !== null) {
234230
return vNode as any as HostElement;
235231
}
236232
vNode =
237233
vnode_getParent(vNode) ||
238234
// If virtual node, than it could be a slot so we need to read its parent.
239-
vnode_getProp<VNode>(vNode, QSlotParent, this.vNodeLocate);
235+
vNode.getProp<VNode>(QSlotParent, this.vNodeLocate);
240236
} else {
241237
vNode = vnode_getParent(vNode);
242238
}
@@ -246,7 +242,7 @@ export class DomContainer extends _SharedContainer implements IClientContainer {
246242

247243
setHostProp<T>(host: HostElement, name: string, value: T): void {
248244
const vNode: VirtualVNode = host as any;
249-
vnode_setProp(vNode, name, value);
245+
vNode.setProp(name, value);
250246
}
251247

252248
getHostProp<T>(host: HostElement, name: string): T | null {
@@ -265,12 +261,12 @@ export class DomContainer extends _SharedContainer implements IClientContainer {
265261
getObjectById = parseInt;
266262
break;
267263
}
268-
return vnode_getProp(vNode, name, getObjectById);
264+
return vNode.getProp(name, getObjectById);
269265
}
270266

271267
ensureProjectionResolved(vNode: VirtualVNode): void {
272-
if ((vNode[VNodeProps.flags] & VNodeFlags.Resolved) === 0) {
273-
vNode[VNodeProps.flags] |= VNodeFlags.Resolved;
268+
if ((vNode.flags & VNodeFlags.Resolved) === 0) {
269+
vNode.flags |= VNodeFlags.Resolved;
274270
const props = vnode_getProps(vNode);
275271
for (let i = 0; i < props.length; i = i + 2) {
276272
const prop = props[i] as string;
@@ -279,7 +275,7 @@ export class DomContainer extends _SharedContainer implements IClientContainer {
279275
if (typeof value == 'string') {
280276
const projection = this.vNodeLocate(value);
281277
props[i + 1] = projection;
282-
vnode_getProp(projection, QSlotParent, (id) => this.vNodeLocate(id));
278+
(projection as VirtualVNode).getProp(QSlotParent, (id) => this.vNodeLocate(id));
283279
}
284280
}
285281
}

packages/qwik/src/core/client/process-vnode-data.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// NOTE: we want to move this function to qwikloader, and therefore this function should not have any external dependencies
22
import { VNodeDataChar, VNodeDataSeparator } from '../shared/vnode-data-types';
3-
import type { ContainerElement, ElementVNode, QDocument } from './types';
3+
import type { ContainerElement, QDocument } from './types';
4+
import type { ElementVNode } from './vnode-impl';
45

56
/**
67
* Process the VNodeData script tags and store the VNodeData in the VNodeDataMap.

packages/qwik/src/core/client/types.ts

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import type { QRL } from '../shared/qrl/qrl.public';
44
import type { Container } from '../shared/types';
55
import type { VNodeJournal } from './vnode';
6+
import type { ElementVNode, VirtualVNode } from './vnode-impl';
67

78
export type ClientAttrKey = string;
89
export type ClientAttrValue = string | null;
@@ -115,37 +116,37 @@ export const enum ElementVNodeProps {
115116
}
116117

117118
/** @internal */
118-
export type ElementVNode = [
119-
/// COMMON: VNodeProps
120-
VNodeFlags.Element, ////////////// 0 - Flags
121-
VNode | null, /////////////// 1 - Parent
122-
VNode | null, /////////////// 2 - Previous sibling
123-
VNode | null, /////////////// 3 - Next sibling
124-
/// SPECIFIC: ElementVNodeProps
125-
VNode | null | undefined, /// 4 - First child - undefined if children need to be materialize
126-
VNode | null | undefined, /// 5 - Last child - undefined if children need to be materialize
127-
Element, //////////////////// 6 - Element
128-
string | undefined, ///////// 7 - tag
129-
/// Props
130-
(string | null)[], /////// 8 - attrs
131-
] & { __brand__: 'ElementVNode' };
119+
// export type ElementVNode = [
120+
// /// COMMON: VNodeProps
121+
// VNodeFlags.Element, ////////////// 0 - Flags
122+
// VNode | null, /////////////// 1 - Parent
123+
// VNode | null, /////////////// 2 - Previous sibling
124+
// VNode | null, /////////////// 3 - Next sibling
125+
// /// SPECIFIC: ElementVNodeProps
126+
// VNode | null | undefined, /// 4 - First child - undefined if children need to be materialize
127+
// VNode | null | undefined, /// 5 - Last child - undefined if children need to be materialize
128+
// Element, //////////////////// 6 - Element
129+
// string | undefined, ///////// 7 - tag
130+
// /// Props
131+
// (string | null)[], /////// 8 - attrs
132+
// ] & { __brand__: 'ElementVNode' };
132133

133134
export const enum TextVNodeProps {
134135
node = 4,
135136
text = 5,
136137
}
137138

138139
/** @internal */
139-
export type TextVNode = [
140-
/// COMMON: VNodeProps
141-
VNodeFlags.Text | VNodeFlags.Inflated, // 0 - Flags
142-
VNode | null, ///////////////// 1 - Parent
143-
VNode | null, ///////////////// 2 - Previous sibling
144-
VNode | null, ///////////////// 3 - Next sibling
145-
/// SPECIFIC: TextVNodeProps
146-
Text | null | undefined, ////// 4 - TextNode or SharedTextNode if Flags.SharedText
147-
string, /////////////////////// 5 - text content
148-
] & { __brand__: 'TextVNode' };
140+
// export type TextVNode = [
141+
// /// COMMON: VNodeProps
142+
// VNodeFlags.Text | VNodeFlags.Inflated, // 0 - Flags
143+
// VNode | null, ///////////////// 1 - Parent
144+
// VNode | null, ///////////////// 2 - Previous sibling
145+
// VNode | null, ///////////////// 3 - Next sibling
146+
// /// SPECIFIC: TextVNodeProps
147+
// Text | null | undefined, ////// 4 - TextNode or SharedTextNode if Flags.SharedText
148+
// string, /////////////////////// 5 - text content
149+
// ] & { __brand__: 'TextVNode' };
149150

150151
export const enum VirtualVNodeProps {
151152
firstChild = ElementVNodeProps.firstChild,
@@ -154,21 +155,21 @@ export const enum VirtualVNodeProps {
154155
}
155156

156157
/** @internal */
157-
export type VirtualVNode = [
158-
/// COMMON: VNodeProps
159-
VNodeFlags.Virtual, ///////////// 0 - Flags
160-
VNode | null, /////////////// 1 - Parent
161-
VNode | null, /////////////// 2 - Previous sibling
162-
VNode | null, /////////////// 3 - Next sibling
163-
/// SPECIFIC: VirtualVNodeProps
164-
VNode | null, /////////////// 4 - First child
165-
VNode | null, /////////////// 5 - Last child
166-
/// Props
167-
(string | null | boolean)[], /////// 6 - attrs
168-
] & { __brand__: 'FragmentNode' & 'HostElement' };
158+
// export type VirtualVNode = [
159+
// /// COMMON: VNodeProps
160+
// VNodeFlags.Virtual, ///////////// 0 - Flags
161+
// VNode | null, /////////////// 1 - Parent
162+
// VNode | null, /////////////// 2 - Previous sibling
163+
// VNode | null, /////////////// 3 - Next sibling
164+
// /// SPECIFIC: VirtualVNodeProps
165+
// VNode | null, /////////////// 4 - First child
166+
// VNode | null, /////////////// 5 - Last child
167+
// /// Props
168+
// (string | null | boolean)[], /////// 6 - attrs
169+
// ] & { __brand__: 'FragmentNode' & 'HostElement' };
169170

170171
/** @internal */
171-
export type VNode = ElementVNode | TextVNode | VirtualVNode;
172+
// export type VNode = ElementVNode | TextVNode | VirtualVNode;
172173

173174
/** @public */
174175
export interface RenderOptions {

0 commit comments

Comments
 (0)