Skip to content

Commit

Permalink
Merge pull request #7149 from QwikDev/v2-remove-process-jsx
Browse files Browse the repository at this point in the history
refactor: remove processJsx method
  • Loading branch information
shairez authored Dec 13, 2024
2 parents 3eb4f34 + e4219ce commit fe61946
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 36 deletions.
8 changes: 2 additions & 6 deletions packages/qwik/src/core/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,12 @@ class DomContainer extends _SharedContainer implements ClientContainer {
getParentHost(host: HostElement): HostElement | null;
// (undocumented)
getSyncFn(id: number): (...args: unknown[]) => unknown;
// Warning: (ae-forgotten-export) The symbol "HostElement" needs to be exported by the entry point index.d.ts
//
// (undocumented)
handleError(err: any, host: HostElement): void;
// (undocumented)
parseQRL<T = unknown>(qrl: string): QRL<T>;
// Warning: (ae-forgotten-export) The symbol "HostElement" needs to be exported by the entry point index.d.ts
//
// (undocumented)
processJsx(host: HostElement, jsx: JSXOutput): ValueOrPromise<void>;
// (undocumented)
qBase: string;
// (undocumented)
Expand Down Expand Up @@ -837,8 +835,6 @@ export abstract class _SharedContainer implements Container {
// (undocumented)
abstract handleError(err: any, $host$: HostElement): void;
// (undocumented)
abstract processJsx(host: HostElement, jsx: JSXOutput): ValueOrPromise<void>;
// (undocumented)
abstract resolveContext<T>(host: HostElement, contextId: ContextId<T>): T | undefined;
// Warning: (ae-forgotten-export) The symbol "SymbolToChunkResolver" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "SerializationContext" needs to be exported by the entry point index.d.ts
Expand Down
10 changes: 0 additions & 10 deletions packages/qwik/src/core/client/dom-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { assertTrue } from '../shared/error/assert';
import { getPlatform } from '../shared/platform/platform';
import type { QRL } from '../shared/qrl/qrl.public';
import { ERROR_CONTEXT, isRecoverable } from '../shared/error/error-handling';
import type { JSXOutput } from '../shared/jsx/types/jsx-node';
import type { ContextId } from '../use/use-context';
import { EMPTY_ARRAY } from '../shared/utils/flyweight';
import { throwErrorAndStop } from '../shared/utils/log';
Expand All @@ -30,10 +29,8 @@ import {
import { isPromise } from '../shared/utils/promises';
import { isSlotProp } from '../shared/utils/prop';
import { qDev } from '../shared/utils/qdev';
import type { ValueOrPromise } from '../shared/utils/types';
import { ChoreType } from '../shared/scheduler';
import {
addComponentStylePrefix,
convertScopedStyleIdsToArray,
convertStyleIdsToString,
} from '../shared/utils/scoped-styles';
Expand Down Expand Up @@ -69,7 +66,6 @@ import {
vnode_setProp,
type VNodeJournal,
} from './vnode';
import { vnode_diff } from './vnode-diff';

/** @public */
export function getDomContainer(element: Element | VNode): IClientContainer {
Expand Down Expand Up @@ -193,12 +189,6 @@ export class DomContainer extends _SharedContainer implements IClientContainer {
return inflateQRL(this, parseQRL(qrl)) as QRL<T>;
}

processJsx(host: HostElement, jsx: JSXOutput): ValueOrPromise<void> {
// console.log('>>>> processJsx', String(host));
const styleScopedId = this.getHostProp<string>(host, QScopedStyle);
return vnode_diff(this, jsx, host as VirtualVNode, addComponentStylePrefix(styleScopedId));
}

handleError(err: any, host: HostElement): void {
if (qDev) {
// Clean vdom
Expand Down
19 changes: 15 additions & 4 deletions packages/qwik/src/core/shared/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,14 @@ import type { JSXOutput } from './jsx/types/jsx-node';
import { Task, TaskFlags, cleanupTask, runTask, type TaskFn } from '../use/use-task';
import { runResource, type ResourceDescriptor } from '../use/use-resource';
import { logWarn, throwErrorAndStop } from './utils/log';
import { isPromise, maybeThen, maybeThenPassError, safeCall } from './utils/promises';
import { isPromise, maybeThenPassError, safeCall } from './utils/promises';
import type { ValueOrPromise } from './utils/types';
import { isDomContainer } from '../client/dom-container';
import {
ElementVNodeProps,
VNodeFlags,
VNodeProps,
type ClientContainer,
type ElementVNode,
type VirtualVNode,
} from '../client/types';
Expand All @@ -110,6 +111,8 @@ import { type DomContainer } from '../client/dom-container';
import { serializeAttribute } from './utils/styles';
import type { OnRenderFn } from './component.public';
import type { Props } from './jsx/jsx-runtime';
import { QScopedStyle } from './utils/markers';
import { addComponentStylePrefix } from './utils/scoped-styles';

// Turn this on to get debug output of what the scheduler is doing.
const DEBUG: boolean = false;
Expand Down Expand Up @@ -334,9 +337,17 @@ export const createScheduler = (
chore.$payload$ as Props | null
),
(jsx) => {
return chore.$type$ === ChoreType.COMPONENT
? maybeThen(container.processJsx(host, jsx), () => jsx)
: jsx;
if (chore.$type$ === ChoreType.COMPONENT) {
const styleScopedId = container.getHostProp<string>(host, QScopedStyle);
return vnode_diff(
container as ClientContainer,
jsx,
host as VirtualVNode,
addComponentStylePrefix(styleScopedId)
);
} else {
return jsx;
}
},
(err: any) => container.handleError(err, host)
);
Expand Down
1 change: 0 additions & 1 deletion packages/qwik/src/core/shared/scheduler.unit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ describe('scheduler', () => {
document = createDocument();
document.body.setAttribute(QContainerAttr, 'paused');
const container = getDomContainer(document.body);
container.processJsx = () => null!;
scheduler = createScheduler(
container,
() => null,
Expand Down
3 changes: 0 additions & 3 deletions packages/qwik/src/core/shared/shared-container.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { JSXOutput } from './jsx/types/jsx-node';
import type { ContextId } from '../use/use-context';
import { trackSignal } from '../use/use-core';
import type { ValueOrPromise } from './utils/types';
import { version } from '../version';
import type { Effect, EffectData } from '../signal/signal';
import type { Signal } from '../signal/signal.public';
Expand Down Expand Up @@ -69,7 +67,6 @@ export abstract class _SharedContainer implements Container {
}

abstract ensureProjectionResolved(host: HostElement): void;
abstract processJsx(host: HostElement, jsx: JSXOutput): ValueOrPromise<void>;
abstract handleError(err: any, $host$: HostElement): void;
abstract getParentHost(host: HostElement): HostElement | null;
abstract setContext<T>(host: HostElement, context: ContextId<T>, value: T): void;
Expand Down
4 changes: 0 additions & 4 deletions packages/qwik/src/core/shared/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import type { JSXOutput } from './jsx/types/jsx-node';
import type { ContextId } from '../use/use-context';
import type { ValueOrPromise } from './utils/types';
import type { VNode } from '../client/types';
import type { ISsrNode, StreamWriter, SymbolToChunkResolver } from '../ssr/ssr-types';
import type { Scheduler } from './scheduler';
Expand All @@ -25,8 +23,6 @@ export interface Container {
readonly $serverData$: Record<string, any>;
$currentUniqueId$: number;

// TODO(misko): I think `processJsx` can be deleted.
processJsx(host: HostElement, jsx: JSXOutput): ValueOrPromise<void>;
handleError(err: any, $host$: HostElement): void;
getParentHost(host: HostElement): HostElement | null;
setContext<T>(host: HostElement, context: ContextId<T>, value: T): void;
Expand Down
8 changes: 0 additions & 8 deletions packages/qwik/src/server/ssr-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,6 @@ class SSRContainer extends _SharedContainer implements ISSRContainer {

ensureProjectionResolved(host: HostElement): void {}

processJsx(host: HostElement, jsx: JSXOutput): void {
/**
* During SSR the output needs to be streamed. So we should never get here, because we can't
* process JSX out of order.
*/
throw new Error('Should not get here.');
}

handleError(err: any, $host$: HostElement): void {
throw err;
}
Expand Down

0 comments on commit fe61946

Please sign in to comment.