Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "chore: move internals out of JSXNode" #7299

Closed
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
4 changes: 2 additions & 2 deletions packages/docs/src/routes/api/qwik/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@
}
],
"kind": "Interface",
"content": "A JSX Node, an internal structure. You probably want to use `JSXOutput` instead.\n\n\n```typescript\nexport interface JSXNode<T extends string | FunctionComponent | unknown = unknown> \n```\n\n\n<table><thead><tr><th>\n\nProperty\n\n\n</th><th>\n\nModifiers\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\n[children](#)\n\n\n</td><td>\n\n\n</td><td>\n\n[JSXChildren](#jsxchildren) \\| null\n\n\n</td><td>\n\n\n</td></tr>\n<tr><td>\n\n[dev?](#)\n\n\n</td><td>\n\n\n</td><td>\n\n[DevJSX](#devjsx)\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n<tr><td>\n\n[key](#)\n\n\n</td><td>\n\n\n</td><td>\n\nstring \\| null\n\n\n</td><td>\n\n\n</td></tr>\n<tr><td>\n\n[props](#)\n\n\n</td><td>\n\n\n</td><td>\n\nT extends [FunctionComponent](#functioncomponent)<!-- -->&lt;infer P&gt; ? P : Record&lt;any, unknown&gt;\n\n\n</td><td>\n\n\n</td></tr>\n<tr><td>\n\n[type](#)\n\n\n</td><td>\n\n\n</td><td>\n\nT\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>",
"content": "A JSX Node, an internal structure. You probably want to use `JSXOutput` instead.\n\n\n```typescript\nexport interface JSXNode<T extends string | FunctionComponent | unknown = unknown> \n```\n\n\n<table><thead><tr><th>\n\nProperty\n\n\n</th><th>\n\nModifiers\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\n[children](#)\n\n\n</td><td>\n\n\n</td><td>\n\n[JSXChildren](#jsxchildren) \\| null\n\n\n</td><td>\n\n\n</td></tr>\n<tr><td>\n\n[dev?](#)\n\n\n</td><td>\n\n\n</td><td>\n\n[DevJSX](#devjsx)\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n<tr><td>\n\n[flags](#)\n\n\n</td><td>\n\n\n</td><td>\n\nnumber\n\n\n</td><td>\n\n\n</td></tr>\n<tr><td>\n\n[immutableProps](#)\n\n\n</td><td>\n\n\n</td><td>\n\nRecord&lt;any, unknown&gt; \\| null\n\n\n</td><td>\n\n\n</td></tr>\n<tr><td>\n\n[key](#)\n\n\n</td><td>\n\n\n</td><td>\n\nstring \\| null\n\n\n</td><td>\n\n\n</td></tr>\n<tr><td>\n\n[props](#)\n\n\n</td><td>\n\n\n</td><td>\n\nT extends [FunctionComponent](#functioncomponent)<!-- -->&lt;infer P&gt; ? P : Record&lt;any, unknown&gt;\n\n\n</td><td>\n\n\n</td></tr>\n<tr><td>\n\n[type](#)\n\n\n</td><td>\n\n\n</td><td>\n\nT\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/render/jsx/types/jsx-node.ts",
"mdFile": "qwik.jsxnode.md"
},
Expand Down Expand Up @@ -1760,7 +1760,7 @@
}
],
"kind": "Function",
"content": "> This API is provided as an alpha preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.\n> \n\nLoad the prefetch graph for the container.\n\nEach Qwik container needs to include its own prefetch graph.\n\n\n```typescript\nPrefetchGraph: (opts?: {\n base?: string;\n manifestHash?: string;\n manifestURL?: string;\n nonce?: string;\n}) => JSXOutput\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\nopts\n\n\n</td><td>\n\n{ base?: string; manifestHash?: string; manifestURL?: string; nonce?: string; }\n\n\n</td><td>\n\n_(Optional)_ Options for the loading prefetch graph.\n\n- `base` - Base of the graph. For a default installation this will default to the q:base value `/build/`<!-- -->. But if more than one MFE is installed on the page, then each MFE needs to have its own base. - `manifestHash` - Hash of the manifest file to load. If not provided the hash will be extracted from the container attribute `q:manifest-hash` and assume the default build file `${base}/q-bundle-graph-${manifestHash}.json`<!-- -->. - `manifestURL` - URL of the manifest file to load if non-standard bundle graph location name.\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\n[JSXOutput](#jsxoutput)",
"content": "> This API is provided as an alpha preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.\n> \n\nLoad the prefetch graph for the container.\n\nEach Qwik container needs to include its own prefetch graph.\n\n\n```typescript\nPrefetchGraph: (opts?: {\n base?: string;\n manifestHash?: string;\n manifestURL?: string;\n nonce?: string;\n}) => JSXNode<\"script\">\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\nopts\n\n\n</td><td>\n\n{ base?: string; manifestHash?: string; manifestURL?: string; nonce?: string; }\n\n\n</td><td>\n\n_(Optional)_ Options for the loading prefetch graph.\n\n- `base` - Base of the graph. For a default installation this will default to the q:base value `/build/`<!-- -->. But if more than one MFE is installed on the page, then each MFE needs to have its own base. - `manifestHash` - Hash of the manifest file to load. If not provided the hash will be extracted from the container attribute `q:manifest-hash` and assume the default build file `${base}/q-bundle-graph-${manifestHash}.json`<!-- -->. - `manifestURL` - URL of the manifest file to load if non-standard bundle graph location name.\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\nJSXNode&lt;\"script\"&gt;",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/components/prefetch.ts",
"mdFile": "qwik.prefetchgraph.md"
},
Expand Down
30 changes: 28 additions & 2 deletions packages/docs/src/routes/api/qwik/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3043,6 +3043,32 @@ _(Optional)_
</td></tr>
<tr><td>

[flags](#)

</td><td>

</td><td>

number

</td><td>

</td></tr>
<tr><td>

[immutableProps](#)

</td><td>

</td><td>

Record&lt;any, unknown&gt; \| null

</td><td>

</td></tr>
<tr><td>

[key](#)

</td><td>
Expand Down Expand Up @@ -3565,7 +3591,7 @@ PrefetchGraph: (opts?: {
manifestHash?: string;
manifestURL?: string;
nonce?: string;
}) => JSXOutput;
}) => JSXNode<"script">;
```

<table><thead><tr><th>
Expand Down Expand Up @@ -3599,7 +3625,7 @@ _(Optional)_ Options for the loading prefetch graph.
</tbody></table>
**Returns:**

[JSXOutput](#jsxoutput)
JSXNode&lt;"script"&gt;

[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/components/prefetch.ts)

Expand Down
13 changes: 8 additions & 5 deletions packages/qwik/src/core/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,9 @@ export { jsx as jsxs }
export const _jsxBranch: <T>(input?: T) => T | undefined;

// Warning: (ae-forgotten-export) The symbol "JsxDevOpts" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "JSXNodeInternal" needs to be exported by the entry point index.d.ts
//
// @internal
export const _jsxC: <T extends string | FunctionComponent<Record<any, unknown>>>(type: T, mutableProps: (T extends FunctionComponent<infer PROPS> ? PROPS : Record<any, unknown>) | null, flags: number, key: string | number | null, dev?: JsxDevOpts) => JSXNodeInternal<T>;
export const _jsxC: <T extends string | FunctionComponent<Record<any, unknown>>>(type: T, mutableProps: (T extends FunctionComponent<infer PROPS> ? PROPS : Record<any, unknown>) | null, flags: number, key: string | number | null, dev?: JsxDevOpts) => JSXNode<T>;

// @public (undocumented)
export type JSXChildren = string | number | boolean | null | undefined | Function | RegExp | JSXChildren[] | Promise<JSXChildren> | Signal<JSXChildren> | JSXNode;
Expand All @@ -440,6 +439,10 @@ export interface JSXNode<T extends string | FunctionComponent | unknown = unknow
// (undocumented)
dev?: DevJSX;
// (undocumented)
flags: number;
// (undocumented)
immutableProps: Record<any, unknown> | null;
// (undocumented)
key: string | null;
// (undocumented)
props: T extends FunctionComponent<infer P> ? P : Record<any, unknown>;
Expand All @@ -451,10 +454,10 @@ export interface JSXNode<T extends string | FunctionComponent | unknown = unknow
export type JSXOutput = JSXNode | string | number | boolean | null | undefined | JSXOutput[];

// @internal
export const _jsxQ: <T extends string>(type: T, mutableProps: Record<any, unknown> | null, immutableProps: Record<any, unknown> | null, children: JSXChildren | null, flags: number, key: string | number | null, dev?: DevJSX) => JSXNodeInternal<T>;
export const _jsxQ: <T extends string>(type: T, mutableProps: Record<any, unknown> | null, immutableProps: Record<any, unknown> | null, children: JSXChildren | null, flags: number, key: string | number | null, dev?: DevJSX) => JSXNode<T>;

// @internal
export const _jsxS: <T extends string>(type: T, mutableProps: Record<any, unknown> | null, immutableProps: Record<any, unknown> | null, flags: number, key: string | number | null, dev?: DevJSX) => JSXNodeInternal<T>;
export const _jsxS: <T extends string>(type: T, mutableProps: Record<any, unknown> | null, immutableProps: Record<any, unknown> | null, flags: number, key: string | number | null, dev?: DevJSX) => JSXNode<T>;

// @public (undocumented)
export type JSXTagName = keyof HTMLElementTagNameMap | Omit<string, keyof HTMLElementTagNameMap>;
Expand Down Expand Up @@ -612,7 +615,7 @@ export const PrefetchGraph: (opts?: {
manifestHash?: string;
manifestURL?: string;
nonce?: string;
}) => JSXOutput;
}) => JSXNode_2<"script">;

// @alpha
export const PrefetchServiceWorker: (opts: {
Expand Down
3 changes: 1 addition & 2 deletions packages/qwik/src/core/components/prefetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { isDev } from '@builder.io/qwik/build';
import { _jsxC } from '../internal';
import type { JSXNode } from '@builder.io/qwik/jsx-runtime';
import { useServerData } from '../use/use-env-data';
import type { JSXOutput } from '../render/jsx/types/jsx-node';

/**
* Install a service worker which will prefetch the bundles.
Expand Down Expand Up @@ -126,7 +125,7 @@ const PREFETCH_CODE = /*#__PURE__*/ ((
*/
export const PrefetchGraph = (
opts: { base?: string; manifestHash?: string; manifestURL?: string; nonce?: string } = {}
): JSXOutput => {
) => {
const isTest = import.meta.env.TEST;
if (isDev && !isTest) {
const props = {
Expand Down
4 changes: 2 additions & 2 deletions packages/qwik/src/core/container/serializers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ import { serializeDerivedSignalFunc } from '../qrl/inlined-fn';
import type { QwikElement } from '../render/dom/virtual-element';
import { assertString, assertTrue } from '../error/assert';
import { Fragment, JSXNodeImpl, isJSXNode } from '../render/jsx/jsx-runtime';
import type { JSXNode } from '@builder.io/qwik/jsx-runtime';
import { Slot } from '../render/jsx/slot.public';
import type { JSXNodeInternal } from '../render/jsx/types/jsx-node';

/**
* - 0, 8, 9, A, B, C, D
Expand Down Expand Up @@ -383,7 +383,7 @@ const FormDataSerializer = /*#__PURE__*/ serializer<FormData>({
},
});

const JSXNodeSerializer = /*#__PURE__*/ serializer<JSXNodeInternal>({
const JSXNodeSerializer = /*#__PURE__*/ serializer<JSXNode>({
$prefix$: '\u0017',
$test$: (v) => isJSXNode(v),
$collect$: (node, collector, leaks) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/qwik/src/core/render/dom/render-dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { isArray, isFunction, isObject, isString, type ValueOrPromise } from '..
import { domToVnode, smartUpdateChildren } from './visitor';
import { SkipRender } from '../jsx/utils.public';
import { isJSXNode, SKIP_RENDER_TYPE, _jsxC, Virtual } from '../jsx/jsx-runtime';
import type { DevJSX, JSXNodeInternal } from '../jsx/types/jsx-node';
import type { DevJSX, JSXNode } from '../jsx/types/jsx-node';
import { executeComponent, shouldWrapFunctional } from '../execute-component';
import type { RenderContext } from '../types';
import { type QwikElement, VIRTUAL, type VirtualElement } from './virtual-element';
Expand Down Expand Up @@ -88,7 +88,7 @@ export class ProcessedJSXNodeImpl implements ProcessedJSXNode {
}

export const processNode = (
node: JSXNodeInternal,
node: JSXNode,
invocationContext?: InvokeContext
): ValueOrPromise<ProcessedJSXNode | ProcessedJSXNode[] | undefined> => {
const { key, type, props, children, flags, immutableProps } = node;
Expand Down
12 changes: 6 additions & 6 deletions packages/qwik/src/core/render/jsx/factory.unit.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { h } from './factory';
import { isJSXNode, Fragment } from './jsx-runtime';
import type { FunctionComponent, JSXNodeInternal } from './types/jsx-node';
import type { FunctionComponent } from './types/jsx-node';
import { type ProcessedJSXNode, processNode } from '../dom/render-dom';
import { test, assert } from 'vitest';

Expand All @@ -19,7 +19,7 @@ test('map multiple nodes, flatten', () => {
'a',
[1, 2].map((n) => h('child', null, n)),
'b'
) as JSXNodeInternal
)
) as ProcessedJSXNode;
assert.deepEqual(v.$children$.length, 4);
assert.deepEqual(v.$children$[0].$text$, 'a');
Expand All @@ -32,7 +32,7 @@ test('map multiple nodes, flatten', () => {

test('one child node', () => {
// <parent><child></child></parent>
const v = processNode(h('parent', null, h('child', null)) as JSXNodeInternal) as ProcessedJSXNode;
const v = processNode(h('parent', null, h('child', null))) as ProcessedJSXNode;
assert.deepEqual(v.$children$.length, 1);
assert.deepEqual(v.$children$[0].$type$, 'child');
assert.deepEqual(v.$children$[0].$props$, {});
Expand All @@ -41,7 +41,7 @@ test('one child node', () => {

test('text w/ expression', () => {
// <div>1 {2} 3</div>
const v = processNode(h('div', null, '1 ', 2, ' 3') as JSXNodeInternal) as ProcessedJSXNode;
const v = processNode(h('div', null, '1 ', 2, ' 3')) as ProcessedJSXNode;
assert.deepEqual(v.$children$[0].$type$, '#text');
assert.deepEqual(v.$children$[0].$text$, '1 ');
assert.deepEqual(v.$children$[0].$key$, null);
Expand All @@ -57,15 +57,15 @@ test('text w/ expression', () => {

test('text child', () => {
// <div>text</div>
const v = processNode(h('div', null, 'text') as JSXNodeInternal) as ProcessedJSXNode;
const v = processNode(h('div', null, 'text')) as ProcessedJSXNode;
assert.deepEqual(v.$children$[0].$type$, '#text');
assert.deepEqual(v.$children$[0].$text$, 'text');
assert.deepEqual(v.$children$[0].$key$, null);
});

test('no children', () => {
// <div/>
const v = processNode(h('div', null) as JSXNodeInternal) as ProcessedJSXNode;
const v = processNode(h('div', null)) as ProcessedJSXNode;
assert.deepEqual(v.$children$, []);
});

Expand Down
12 changes: 6 additions & 6 deletions packages/qwik/src/core/render/jsx/jsx-runtime.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DevJSX, FunctionComponent, JSXNode, JSXNodeInternal } from './types/jsx-node';
import type { DevJSX, FunctionComponent, JSXNode } from './types/jsx-node';
import type { QwikJSX } from './types/jsx-qwik';
import { qDev, qRuntimeQrl, seal } from '../../util/qdev';
import { logError, logOnceWarn, logWarn } from '../../util/log';
Expand Down Expand Up @@ -34,7 +34,7 @@ export const _jsxQ = <T extends string>(
flags: number,
key: string | number | null,
dev?: DevJSX
): JSXNodeInternal<T> => {
): JSXNode<T> => {
assertString(type, 'jsx type must be a string');
const processed = key == null ? null : String(key);
const node = new JSXNodeImpl<T>(
Expand Down Expand Up @@ -68,7 +68,7 @@ export const _jsxS = <T extends string>(
flags: number,
key: string | number | null,
dev?: DevJSX
): JSXNodeInternal<T> => {
): JSXNode<T> => {
let children: JSXChildren = null;
if (mutableProps && 'children' in mutableProps) {
children = mutableProps.children as JSXChildren;
Expand All @@ -88,7 +88,7 @@ export const _jsxC = <T extends string | FunctionComponent<Record<any, unknown>>
flags: number,
key: string | number | null,
dev?: JsxDevOpts
): JSXNodeInternal<T> => {
): JSXNode<T> => {
const processed = key == null ? null : String(key);
const props = mutableProps ?? ({} as NonNullable<typeof mutableProps>);
// In dynamic components, type could be a string
Expand Down Expand Up @@ -196,7 +196,7 @@ export const RenderOnce: FunctionComponent<{
return new JSXNodeImpl(Virtual, EMPTY_OBJ, null, props.children, static_subtree, key);
};

const validateJSXNode = (node: JSXNodeInternal) => {
const validateJSXNode = (node: JSXNode) => {
if (qDev) {
const { type, props, immutableProps, children } = node;
invoke(undefined, () => {
Expand Down Expand Up @@ -321,7 +321,7 @@ const printObjectLiteral = (obj: Record<string, unknown>) => {
.join(', ')} }`;
};

export const isJSXNode = (n: unknown): n is JSXNodeInternal => {
export const isJSXNode = (n: unknown): n is JSXNode => {
if (qDev) {
if (n instanceof JSXNodeImpl) {
return true;
Expand Down
16 changes: 6 additions & 10 deletions packages/qwik/src/core/render/jsx/jsx-runtime.unit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assert, test } from 'vitest';
import { type ProcessedJSXNode, processNode } from '../dom/render-dom';
import { jsx, isJSXNode, Fragment } from './jsx-runtime';
import type { FunctionComponent, JSXNodeInternal } from './types/jsx-node';
import type { FunctionComponent } from './types/jsx-node';

test('map multiple nodes', () => {
// <parent>
Expand All @@ -10,7 +10,7 @@ test('map multiple nodes', () => {
const v = processNode(
jsx('parent', {
children: [1, 2].map((n) => jsx('child', { children: n })),
}) as JSXNodeInternal
})
) as ProcessedJSXNode;
assert.deepEqual(v.$children$.length, 2);
assert.deepEqual(v.$children$[0].$type$, 'child');
Expand All @@ -19,9 +19,7 @@ test('map multiple nodes', () => {

test('one child node', () => {
// <parent><child></child></parent>
const v = processNode(
jsx('parent', { children: jsx('child', {}) }) as JSXNodeInternal
) as ProcessedJSXNode;
const v = processNode(jsx('parent', { children: jsx('child', {}) })) as ProcessedJSXNode;
assert.deepEqual(v.$children$.length, 1);
assert.deepEqual(v.$children$[0].$type$, 'child');
assert.deepEqual(v.$children$[0].$props$, {});
Expand All @@ -30,9 +28,7 @@ test('one child node', () => {

test('text w/ expression', () => {
// <div>1 {2} 3</div>
const v = processNode(
jsx('div', { children: ['1 ', 2, ' 3'] }) as JSXNodeInternal
) as ProcessedJSXNode;
const v = processNode(jsx('div', { children: ['1 ', 2, ' 3'] })) as ProcessedJSXNode;
assert.deepEqual(v.$children$[0].$type$, '#text');
assert.deepEqual(v.$children$[0].$text$, '1 ');
assert.deepEqual(v.$children$[0].$key$, null);
Expand All @@ -48,15 +44,15 @@ test('text w/ expression', () => {

test('text child', () => {
// <div>text</div>
const v = processNode(jsx('div', { children: 'text' }) as JSXNodeInternal) as ProcessedJSXNode;
const v = processNode(jsx('div', { children: 'text' })) as ProcessedJSXNode;
assert.deepEqual(v.$children$[0].$type$, '#text');
assert.deepEqual(v.$children$[0].$text$, 'text');
assert.deepEqual(v.$children$[0].$key$, null);
});

test('no children', () => {
// <div/>
const v = processNode(jsx('div', {}) as JSXNodeInternal) as ProcessedJSXNode;
const v = processNode(jsx('div', {})) as ProcessedJSXNode;
assert.deepEqual(v.$children$, []);
});
test('key', () => {
Expand Down
13 changes: 2 additions & 11 deletions packages/qwik/src/core/render/jsx/types/jsx-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,9 @@ export interface DevJSX {
export interface JSXNode<T extends string | FunctionComponent | unknown = unknown> {
type: T;
props: T extends FunctionComponent<infer P> ? P : Record<any, unknown>;
immutableProps: Record<any, unknown> | null;
children: JSXChildren | null;
flags: number;
key: string | null;
dev?: DevJSX;
}

/**
* The internal representation of a JSX node.
*
* @internal
*/
export interface JSXNodeInternal<T extends string | FunctionComponent | unknown = unknown>
extends JSXNode<T> {
immutableProps: Record<any, unknown> | null;
flags: number;
}
Loading