Skip to content

Commit

Permalink
Merge pull request #7334 from QwikDev/stuff
Browse files Browse the repository at this point in the history
perf: don't bundle core in server or optimizer
  • Loading branch information
wmertens authored Feb 15, 2025
2 parents a6ea466 + 266ca03 commit 9f1e5fa
Show file tree
Hide file tree
Showing 42 changed files with 339 additions and 294 deletions.
5 changes: 2 additions & 3 deletions packages/qwik/src/core/client/dom-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ERROR_CONTEXT, isRecoverable } from '../shared/error/error-handling';
import { getPlatform } from '../shared/platform/platform';
import { emitEvent } from '../shared/qrl/qrl-class';
import type { QRL } from '../shared/qrl/qrl.public';
import { ChoreType } from '../shared/scheduler';
import { ChoreType } from '../shared/util-chore-type';
import { _SharedContainer } from '../shared/shared-container';
import { inflateQRL, parseQRL, wrapDeserializerProxy } from '../shared/shared-serialization';
import { QContainerValue, type HostElement, type ObjToProxyMap } from '../shared/types';
Expand Down Expand Up @@ -51,8 +51,6 @@ import {
} from './types';
import {
VNodeJournalOpCode,
mapArray_get,
mapArray_set,
vnode_applyJournal,
vnode_getDOMChildNodes,
vnode_getDomParent,
Expand All @@ -67,6 +65,7 @@ import {
vnode_setProp,
type VNodeJournal,
} from './vnode';
import { mapArray_get, mapArray_set } from './util-mapArray';

/** @public */
export function getDomContainer(element: Element | VNode): IClientContainer {
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik/src/core/client/dom-render.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { FunctionComponent, JSXNode, JSXOutput } from '../shared/jsx/types/jsx-node';
import { isDocument, isElement } from '../shared/utils/element';
import { ChoreType } from '../shared/scheduler';
import { ChoreType } from '../shared/util-chore-type';
import { QContainerValue } from '../shared/types';
import { DomContainer, getDomContainer } from './dom-container';
import { cleanup } from './vnode-diff';
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik/src/core/client/queue-qrl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { QError, qError } from '../shared/error/error';
import type { QRLInternal } from '../shared/qrl/qrl-class';
import { ChoreType } from '../shared/scheduler';
import { ChoreType } from '../shared/util-chore-type';
import { getInvokeContext } from '../use/use-core';
import { useLexicalScope } from '../use/use-lexical-scope.public';
import { _getQContainerElement, getDomContainer } from './dom-container';
Expand Down
70 changes: 70 additions & 0 deletions packages/qwik/src/core/client/util-mapArray.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { assertTrue } from '../shared/error/assert';

export const mapApp_findIndx = <T>(
elementVNode: (T | null)[],
key: string,
start: number
): number => {
assertTrue(start % 2 === 0, 'Expecting even number.');
let bottom = (start as number) >> 1;
let top = (elementVNode.length - 2) >> 1;
while (bottom <= top) {
const mid = bottom + ((top - bottom) >> 1);
const midKey = elementVNode[mid << 1] as string;
if (midKey === key) {
return mid << 1;
}
if (midKey < key) {
bottom = mid + 1;
} else {
top = mid - 1;
}
}
return (bottom << 1) ^ -1;
};

export const mapArray_set = <T>(
elementVNode: (T | null)[],
key: string,
value: T | null,
start: number
) => {
const indx = mapApp_findIndx(elementVNode, key, start);
if (indx >= 0) {
if (value == null) {
elementVNode.splice(indx, 2);
} else {
elementVNode[indx + 1] = value;
}
} else if (value != null) {
elementVNode.splice(indx ^ -1, 0, key as any, value);
}
};

export const mapApp_remove = <T>(
elementVNode: (T | null)[],
key: string,
start: number
): T | null => {
const indx = mapApp_findIndx(elementVNode, key, start);
let value: T | null = null;
if (indx >= 0) {
value = elementVNode[indx + 1];
elementVNode.splice(indx, 2);
return value;
}
return value;
};

export const mapArray_get = <T>(
elementVNode: (T | null)[],
key: string,
start: number
): T | null => {
const indx = mapApp_findIndx(elementVNode, key, start);
if (indx >= 0) {
return elementVNode[indx + 1] as T | null;
} else {
return null;
}
};
6 changes: 3 additions & 3 deletions packages/qwik/src/core/client/vnode-diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {
isHtmlAttributeAnEventName,
isJsxPropertyAnEventName,
} from '../shared/utils/event-names';
import { ChoreType } from '../shared/scheduler';
import { ChoreType } from '../shared/util-chore-type';
import { hasClassAttr } from '../shared/utils/scoped-styles';
import type { HostElement, QElement, QwikLoaderEventScope, qWindow } from '../shared/types';
import { DEBUG_TYPE, QContainerValue, VirtualType } from '../shared/types';
Expand All @@ -60,8 +60,6 @@ import {
type VirtualVNode,
} from './types';
import {
mapApp_findIndx,
mapArray_set,
vnode_ensureElementInflated,
vnode_getAttr,
vnode_getDomParentVNode,
Expand Down Expand Up @@ -92,6 +90,8 @@ import {
vnode_walkVNode,
type VNodeJournal,
} from './vnode';
import { mapApp_findIndx } from './util-mapArray';
import { mapArray_set } from './util-mapArray';
import { getNewElementNamespaceData } from './vnode-namespace';
import { WrappedSignal, EffectProperty, isSignal, EffectPropData } from '../signal/signal';
import type { Signal } from '../signal/signal.public';
Expand Down
78 changes: 4 additions & 74 deletions packages/qwik/src/core/client/vnode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@
import { isDev } from '@qwik.dev/core/build';
import { qwikDebugToString } from '../debug';
import { assertDefined, assertEqual, assertFalse, assertTrue } from '../shared/error/assert';
import { QError, qError } from '../shared/error/error';
import { DEBUG_TYPE, QContainerValue, VirtualType, VirtualTypeName } from '../shared/types';
import { escapeHTML } from '../shared/utils/character-escaping';
import { isText } from '../shared/utils/element';
import {
ELEMENT_ID,
Expand All @@ -146,9 +149,9 @@ import {
dangerouslySetInnerHTML,
} from '../shared/utils/markers';
import { isHtmlElement } from '../shared/utils/types';
import { DEBUG_TYPE, QContainerValue, VirtualType, VirtualTypeName } from '../shared/types';
import { VNodeDataChar } from '../shared/vnode-data-types';
import { getDomContainer } from './dom-container';
import { mapApp_findIndx, mapArray_get, mapArray_set } from './util-mapArray';
import {
ElementVNodeProps,
TextVNodeProps,
Expand All @@ -168,8 +171,6 @@ import {
vnode_getDomChildrenWithCorrectNamespacesToInsert,
vnode_getElementNamespaceFlags,
} from './vnode-namespace';
import { escapeHTML } from '../shared/utils/character-escaping';
import { QError, qError } from '../shared/error/error';

//////////////////////////////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -934,77 +935,6 @@ export const vnode_applyJournal = (journal: VNodeJournal) => {

//////////////////////////////////////////////////////////////////////////////////////////////////////

export const mapApp_findIndx = <T>(
elementVNode: (T | null)[],
key: string,
start: number
): number => {
assertTrue(start % 2 === 0, 'Expecting even number.');
let bottom = (start as number) >> 1;
let top = (elementVNode.length - 2) >> 1;
while (bottom <= top) {
const mid = bottom + ((top - bottom) >> 1);
const midKey = elementVNode[mid << 1] as string;
if (midKey === key) {
return mid << 1;
}
if (midKey < key) {
bottom = mid + 1;
} else {
top = mid - 1;
}
}
return (bottom << 1) ^ -1;
};

export const mapArray_set = <T>(
elementVNode: (T | null)[],
key: string,
value: T | null,
start: number
) => {
const indx = mapApp_findIndx(elementVNode, key, start);
if (indx >= 0) {
if (value == null) {
elementVNode.splice(indx, 2);
} else {
elementVNode[indx + 1] = value;
}
} else if (value != null) {
elementVNode.splice(indx ^ -1, 0, key as any, value);
}
};

export const mapApp_remove = <T>(
elementVNode: (T | null)[],
key: string,
start: number
): T | null => {
const indx = mapApp_findIndx(elementVNode, key, start);
let value: T | null = null;
if (indx >= 0) {
value = elementVNode[indx + 1];
elementVNode.splice(indx, 2);
return value;
}
return value;
};

export const mapArray_get = <T>(
elementVNode: (T | null)[],
key: string,
start: number
): T | null => {
const indx = mapApp_findIndx(elementVNode, key, start);
if (indx >= 0) {
return elementVNode[indx + 1] as T | null;
} else {
return null;
}
};

//////////////////////////////////////////////////////////////////////////////////////////////////////

export const vnode_insertBefore = (
journal: VNodeJournal,
parent: ElementVNode | VirtualVNode,
Expand Down
19 changes: 10 additions & 9 deletions packages/qwik/src/core/shared/component-execution.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { isDev } from '@qwik.dev/core/build';
import { vnode_isVNode } from '../client/vnode';
import { Slot } from '../shared/jsx/slot.public';
import { EffectProperty, getSubscriber, isSignal } from '../signal/signal';
import { clearVNodeEffectDependencies } from '../signal/signal-subscriber';
import { invokeApply, newInvokeContext, untrack } from '../use/use-core';
import { type EventQRL, type UseOnMap } from '../use/use-on';
import { isQwikComponent, type OnRenderFn } from './component.public';
import { assertDefined } from './error/assert';
import { isQrl, type QRLInternal } from './qrl/qrl-class';
import { Fragment, JSXNodeImpl, _jsxSorted, isJSXNode, type Props } from './jsx/jsx-runtime';
import type { JSXNodeInternal, JSXOutput } from './jsx/types/jsx-node';
import type { KnownEventNames } from './jsx/types/jsx-qwik-events';
import { invokeApply, newInvokeContext, untrack } from '../use/use-core';
import { type EventQRL, type UseOnMap } from '../use/use-on';
import type { QRLInternal } from './qrl/qrl-class';
import { isQrl } from './qrl/qrl-utils';
import type { Container, HostElement } from './types';
import { EMPTY_OBJ } from './utils/flyweight';
import { logWarn } from './utils/log';
import {
ELEMENT_PROPS,
ELEMENT_SEQ_IDX,
Expand All @@ -18,12 +25,6 @@ import {
} from './utils/markers';
import { MAX_RETRY_ON_PROMISE_COUNT, isPromise, maybeThen, safeCall } from './utils/promises';
import type { ValueOrPromise } from './utils/types';
import type { Container, HostElement } from './types';
import { logWarn } from './utils/log';
import { EffectProperty, isSignal, getSubscriber } from '../signal/signal';
import { vnode_isVNode } from '../client/vnode';
import { clearVNodeEffectDependencies } from '../signal/signal-subscriber';
import { Slot } from '../shared/jsx/slot.public';

/**
* Use `executeComponent` to execute a component.
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik/src/core/shared/component.public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import type {
import type { FunctionComponent } from './jsx/types/jsx-node';
import { _CONST_PROPS, _VAR_PROPS, _jsxSorted, _jsxSplit } from '../internal';
import type { QwikIntrinsicElements } from './jsx/types/jsx-qwik-elements';
import { assertQrl } from './qrl/qrl-class';
import { assertNumber } from './error/assert';
import { qTest } from './utils/qdev';
import { assertQrl } from './qrl/qrl-utils';

// TS way to check for any
type IsAny<T> = 0 extends T & 1 ? true : false;
Expand Down
4 changes: 2 additions & 2 deletions packages/qwik/src/core/shared/platform/platform.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// keep this import from core/build so the cjs build works
import { isServer } from '@qwik.dev/core/build';
import { QError, qError } from '../error/error';
import { getSymbolHash } from '../qrl/qrl-class';
import { getSymbolHash } from '../qrl/qrl-utils';
import { QBaseAttr } from '../utils/markers';
import { qDynamicPlatform } from '../utils/qdev';
import type { CorePlatform } from './types';
import { QBaseAttr } from '../utils/markers';

export const createPlatform = (): CorePlatform => {
return {
Expand Down
39 changes: 1 addition & 38 deletions packages/qwik/src/core/shared/qrl/qrl-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,16 @@ import { getQFuncs, QInstanceAttr } from '../utils/markers';
import { isPromise, maybeThen } from '../utils/promises';
import { qDev, qSerialize, qTest, seal } from '../utils/qdev';
import { isArray, isFunction, type ValueOrPromise } from '../utils/types';
import { isSignal } from '../../signal/signal';
import type { QRLDev } from './qrl';
import type { QRL, QrlArgs, QrlReturn } from './qrl.public';
import type { Signal } from '../../signal/signal.public';

export const isQrl = <T = unknown>(value: unknown): value is QRLInternal<T> => {
return typeof value === 'function' && typeof (value as any).getSymbol === 'function';
};

// Make sure this value is same as value in `platform.ts`
export const SYNC_QRL = '<sync>';
import { getSymbolHash, SYNC_QRL } from './qrl-utils';

interface SyncQRLSymbol {
$symbol$: typeof SYNC_QRL;
}

export type SyncQRLInternal = QRLInternal & SyncQRLSymbol;

/** Sync QRL is a function which is serialized into `<script q:func="qwik/json">` tag. */
export const isSyncQrl = (value: any): value is SyncQRLInternal => {
return isQrl(value) && value.$symbol$ == SYNC_QRL;
};

export type QRLInternalMethods<TYPE> = {
readonly $chunk$: string | null;
readonly $symbol$: string;
Expand Down Expand Up @@ -254,30 +241,6 @@ export const createQRL = <TYPE>(
return qrl;
};

export const getSymbolHash = (symbolName: string) => {
const index = symbolName.lastIndexOf('_');
if (index > -1) {
return symbolName.slice(index + 1);
}
return symbolName;
};

export function assertQrl<T>(qrl: QRL<T>): asserts qrl is QRLInternal<T> {
if (qDev) {
if (!isQrl(qrl)) {
throw new Error('Not a QRL');
}
}
}

export function assertSignal<T>(obj: unknown): asserts obj is Signal<T> {
if (qDev) {
if (!isSignal(obj) && !isSignal(obj)) {
throw new Error('Not a Signal');
}
}
}

const EMITTED = /*#__PURE__*/ new Set();

export const emitUsedSymbol = (symbol: string, element: Element | undefined, reqTime: number) => {
Expand Down
Loading

0 comments on commit 9f1e5fa

Please sign in to comment.