Skip to content

chore: minify some class props from core #7609

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

Open
wants to merge 2 commits into
base: build/v2
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion packages/qwik/src/core/client/dom-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ export class DomContainer extends _SharedContainer implements IClientContainer {
containerAttributes[attr.name] = attr.value;
}
}
this.$serverData$ = { containerAttributes };
this.serverData = { containerAttributes };
}

/**
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
Expand Up @@ -40,7 +40,7 @@ export const render = async (
(parent as Element).setAttribute(QContainerAttr, QContainerValue.RESUMED);

const container = getDomContainer(parent as HTMLElement) as DomContainer;
container.$serverData$ = opts.serverData || {};
container.serverData = opts.serverData || {};
const host = container.rootVNode;
container.$scheduler$(ChoreType.NODE_DIFF, host, host, jsxNode as JSXNode);
await container.$scheduler$(ChoreType.WAIT_FOR_ALL);
Expand Down
4 changes: 2 additions & 2 deletions packages/qwik/src/core/qwik.core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -870,8 +870,6 @@ export abstract class _SharedContainer implements Container {
// (undocumented)
readonly $scheduler$: Scheduler;
// (undocumented)
$serverData$: Record<string, any>;
// (undocumented)
readonly $storeProxyMap$: ObjToProxyMap;
// (undocumented)
readonly $version$: string;
Expand Down Expand Up @@ -901,6 +899,8 @@ export abstract class _SharedContainer implements Container {
};
} | null, symbolToChunkResolver: SymbolToChunkResolver, writer?: StreamWriter, prepVNodeData?: (vNode: any) => void): SerializationContext;
// (undocumented)
serverData: Record<string, any>;
// (undocumented)
abstract setContext<T>(host: HostElement, context: ContextId<T>, value: T): void;
// (undocumented)
abstract setHostProp<T>(host: HostElement, name: string, value: T): void;
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik/src/core/reactive-primitives/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const addQrlToSerializationCtx = (
qrl = container.getHostProp<QRL>(effect as ISsrNode, OnRenderProp);
}
if (qrl) {
(container as SSRContainer).serializationCtx.$eventQrls$.add(qrl);
(container as SSRContainer).serializationCtx.eventQrls.add(qrl);
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions packages/qwik/src/core/shared/shared-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export abstract class _SharedContainer implements Container {
readonly $locale$: string;
/// Retrieve Object from paused serialized state.
readonly $getObjectById$: (id: number | string) => any;
$serverData$: Record<string, any>;
serverData: Record<string, any>;
$currentUniqueId$ = 0;
$instanceHash$: string | null = null;
$buildBase$: string | null = null;
Expand All @@ -29,7 +29,7 @@ export abstract class _SharedContainer implements Container {
serverData: Record<string, any>,
locale: string
) {
this.$serverData$ = serverData;
this.serverData = serverData;
this.$locale$ = locale;
this.$version$ = version;
this.$storeProxyMap$ = new WeakMap();
Expand Down
49 changes: 28 additions & 21 deletions packages/qwik/src/core/shared/shared-serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ type SeenRef = {
let isDomRef = (obj: unknown): obj is DomRef => false;

export interface SerializationContext {
$serialize$: () => void;
serialize: () => void;

$symbolToChunkResolver$: SymbolToChunkResolver;

Expand All @@ -647,7 +647,7 @@ export interface SerializationContext {
* Returns a path string representing the path from roots through all parents to the object.
* Format: "3 2 0" where each number is the index within its parent, from root to leaf.
*/
$addRoot$: (obj: unknown, parent?: unknown) => number;
addRoot: (obj: unknown, parent?: unknown) => number;

/**
* Get root path of the object without creating a new root.
Expand All @@ -660,7 +660,7 @@ export interface SerializationContext {

$seen$: (obj: unknown, parent: unknown | null, index: number) => void;

$roots$: unknown[];
roots: unknown[];
$pathMap$: Map<unknown, string | number>;

$addSyncFn$($funcStr$: string | null, argsCount: number, fn: Function): number;
Expand All @@ -671,7 +671,7 @@ export interface SerializationContext {
$writer$: StreamWriter;
$syncFns$: string[];

$eventQrls$: Set<QRL>;
eventQrls: Set<QRL>;
$eventNames$: Set<string>;
$resources$: Set<ResourceReturnInternal<unknown>>;
$renderSymbols$: Set<string>;
Expand Down Expand Up @@ -748,7 +748,7 @@ export const createSerializationContext = (
return pathStr;
};

const $addRoot$ = (obj: any, parent: unknown = null) => {
const addRoot = (obj: any, parent: unknown = null) => {
let seen = seenObjsMap.get(obj);
if (!seen) {
const rootIndex = roots.length;
Expand All @@ -771,20 +771,20 @@ export const createSerializationContext = (
) as (obj: unknown) => obj is DomRef;

return {
async $serialize$(): Promise<void> {
async serialize(): Promise<void> {
return await serialize(this);
},
$isSsrNode$: isSsrNode,
$isDomRef$: isDomRef,
$symbolToChunkResolver$: symbolToChunkResolver,
$wasSeen$,
$roots$: roots,
roots,
$seen$,
$hasRootId$: (obj: any) => {
const id = seenObjsMap.get(obj);
return id?.$parent$ === null ? id.$index$ : undefined;
},
$addRoot$,
addRoot,
$addRootPath$,
$syncFns$: syncFns,
$addSyncFn$: (funcStr: string | null, argCount: number, fn: Function) => {
Expand All @@ -809,7 +809,7 @@ export const createSerializationContext = (
return id;
},
$writer$: writer,
$eventQrls$: new Set<QRL>(),
eventQrls: new Set<QRL>(),
$eventNames$: new Set<string>(),
$resources$: new Set<ResourceReturnInternal<unknown>>(),
$renderSymbols$: new Set<string>(),
Expand All @@ -827,7 +827,7 @@ function $discoverRoots$(
parent: unknown,
index: number
): void {
const { $wasSeen$, $seen$, $addRoot$ } = serializationContext;
const { $wasSeen$, $seen$, addRoot: $addRoot$ } = serializationContext;
if (!(shouldTrackObj(obj) || frameworkType(obj))) {
return;
}
Expand Down Expand Up @@ -879,8 +879,15 @@ class PromiseResult {
* - Therefore root indexes need to be doubled to get the actual index.
*/
async function serialize(serializationContext: SerializationContext): Promise<void> {
const { $writer$, $isSsrNode$, $isDomRef$, $storeProxyMap$, $addRoot$, $pathMap$, $wasSeen$ } =
serializationContext;
const {
$writer$,
$isSsrNode$,
$isDomRef$,
$storeProxyMap$,
addRoot: $addRoot$,
$pathMap$,
$wasSeen$,
} = serializationContext;
let depth = 0;
const forwardRefs: number[] = [];
let forwardRefsId = 0;
Expand Down Expand Up @@ -930,7 +937,7 @@ async function serialize(serializationContext: SerializationContext): Promise<vo

const addPreloadQrl = (qrl: QRLInternal) => {
preloadQrls.add(qrl);
serializationContext.$addRoot$(qrl, null);
serializationContext.addRoot(qrl, null);
};

const outputRootRef = (value: unknown, elseCallback: () => void) => {
Expand Down Expand Up @@ -964,7 +971,7 @@ async function serialize(serializationContext: SerializationContext): Promise<vo
if (isRootObject()) {
output(type, qrl);
} else {
const id = serializationContext.$addRoot$(qrl);
const id = serializationContext.addRoot(qrl);
output(type, id);
}
});
Expand Down Expand Up @@ -1092,7 +1099,7 @@ async function serialize(serializationContext: SerializationContext): Promise<vo
if ($storeProxyMap$.has(propValue)) {
const innerStore = $storeProxyMap$.get(propValue);
innerStores.push(innerStore);
serializationContext.$addRoot$(innerStore);
serializationContext.addRoot(innerStore);
}
}

Expand Down Expand Up @@ -1318,7 +1325,7 @@ async function serialize(serializationContext: SerializationContext): Promise<vo
$writer$.write('[');

let lastRootsLength = 0;
let rootsLength = serializationContext.$roots$.length;
let rootsLength = serializationContext.roots.length;
while (lastRootsLength < rootsLength || promises.size) {
if (lastRootsLength !== 0) {
$writer$.write(',');
Expand All @@ -1331,7 +1338,7 @@ async function serialize(serializationContext: SerializationContext): Promise<vo
} else {
separator = true;
}
writeValue(serializationContext.$roots$[i]);
writeValue(serializationContext.roots[i]);
}

if (promises.size) {
Expand All @@ -1343,7 +1350,7 @@ async function serialize(serializationContext: SerializationContext): Promise<vo
}

lastRootsLength = rootsLength;
rootsLength = serializationContext.$roots$.length;
rootsLength = serializationContext.roots.length;
}

if (forwardRefs.length) {
Expand Down Expand Up @@ -1462,7 +1469,7 @@ export function qrlToString(
serializedReferences += ' ';
}
// We refer by id so every capture needs to be a root
serializedReferences += serializationContext.$addRoot$(value.$captureRef$[i]);
serializedReferences += serializationContext.addRoot(value.$captureRef$[i]);
}
qrlStringInline += `[${serializedReferences}]`;
} else if (value.$capture$ && value.$capture$.length > 0) {
Expand All @@ -1488,9 +1495,9 @@ export async function _serialize(data: unknown[]): Promise<string> {
);

for (const root of data) {
serializationContext.$addRoot$(root);
serializationContext.addRoot(root);
}
await serializationContext.$serialize$();
await serializationContext.serialize();
return serializationContext.$writer$.toString();
}

Expand Down
4 changes: 2 additions & 2 deletions packages/qwik/src/core/shared/shared-serialization.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1064,9 +1064,9 @@ async function serialize(...roots: any[]): Promise<any[]> {
null!
);
for (const root of roots) {
sCtx.$addRoot$(root, null);
sCtx.addRoot(root, null);
}
await sCtx.$serialize$();
await sCtx.serialize();
const objs = JSON.parse(sCtx.$writer$.toString());
// eslint-disable-next-line no-console
DEBUG && console.log(objs);
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik/src/core/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface Container {
readonly $locale$: string;
/// Retrieve Object from paused serialized state.
readonly $getObjectById$: (id: number | string) => any;
readonly $serverData$: Record<string, any>;
readonly serverData: Record<string, any>;
$currentUniqueId$: number;
$buildBase$: string | null;

Expand Down
2 changes: 1 addition & 1 deletion packages/qwik/src/core/ssr/ssr-render-jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ function addQwikEventToSerializationContext(
const eventName = getEventNameFromJsxEvent(key);
if (eventName) {
serializationCtx.$eventNames$.add(eventName);
serializationCtx.$eventQrls$.add(qrl);
serializationCtx.eventQrls.add(qrl);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/qwik/src/core/use/use-env-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export function useServerData<T, B = T>(key: string, defaultValue: B): T | B;
/** @public */
export function useServerData(key: string, defaultValue?: any) {
const ctx = tryGetInvokeContext();
return ctx?.$container$?.$serverData$[key] ?? defaultValue;
return ctx?.$container$?.serverData[key] ?? defaultValue;
}
16 changes: 8 additions & 8 deletions packages/qwik/src/server/ssr-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ class SSRContainer extends _SharedContainer implements ISSRContainer {
containerAttributes[QManifestHashAttr] = this.resolvedManifest.manifest.manifestHash;
containerAttributes[QInstanceAttr] = this.$instanceHash$;

this.$serverData$.containerAttributes = containerAttributes;
this.serverData.containerAttributes = containerAttributes;

const containerAttributeArray = Object.entries(containerAttributes).reduce<string[]>(
(acc, [key, value]) => {
Expand Down Expand Up @@ -473,7 +473,7 @@ class SSRContainer extends _SharedContainer implements ISSRContainer {
const componentFrame = this.getComponentFrame();
if (componentFrame) {
// TODO: we should probably serialize only projection VNode
this.serializationCtx.$addRoot$(componentFrame.componentNode);
this.serializationCtx.addRoot(componentFrame.componentNode);
componentFrame.projectionDepth++;
}
}
Expand Down Expand Up @@ -538,7 +538,7 @@ class SSRContainer extends _SharedContainer implements ISSRContainer {
if (this.$noMoreRoots$) {
return this.serializationCtx.$hasRootId$(obj);
}
return this.serializationCtx.$addRoot$(obj);
return this.serializationCtx.addRoot(obj);
}

getLastNode(): ISsrNode {
Expand Down Expand Up @@ -644,7 +644,7 @@ class SSRContainer extends _SharedContainer implements ISSRContainer {
* skipped. By choosing different separators we can encode different numbers of elements to skip.
*/
emitVNodeData() {
if (!this.serializationCtx.$roots$.length) {
if (!this.serializationCtx.roots.length) {
return;
}
this.openElement('script', ['type', 'qwik/vnode']);
Expand Down Expand Up @@ -825,11 +825,11 @@ class SSRContainer extends _SharedContainer implements ISSRContainer {
}

private emitStateData(): ValueOrPromise<void> {
if (!this.serializationCtx.$roots$.length) {
if (!this.serializationCtx.roots.length) {
return;
}
this.openElement('script', ['type', 'qwik/state']);
return maybeThen(this.serializationCtx.$serialize$(), () => {
return maybeThen(this.serializationCtx.serialize(), () => {
this.closeElement();
});
}
Expand All @@ -851,7 +851,7 @@ class SSRContainer extends _SharedContainer implements ISSRContainer {
}

private emitPreloads() {
const qrls = Array.from(this.serializationCtx.$eventQrls$) as QRLInternal[];
const qrls = Array.from(this.serializationCtx.eventQrls) as QRLInternal[];
/**
* Skip preloader injection if preloader is exactly `null` or if there are no qrls (since then
* there is no reactivity)
Expand All @@ -863,7 +863,7 @@ class SSRContainer extends _SharedContainer implements ISSRContainer {
}

isStatic(): boolean {
return this.serializationCtx.$eventQrls$.size === 0;
return this.serializationCtx.eventQrls.size === 0;
}

private getQwikLoaderPositionMode() {
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik/src/server/ssr-render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function getSnapshotResult(ssrContainer: SSRContainer): SnapshotResult {
? {
funcs: Array.from(ssrContainer.serializationCtx.$syncFns$),
mode: canRender ? 'render' : 'listeners',
qrls: Array.from(ssrContainer.serializationCtx.$eventQrls$),
qrls: Array.from(ssrContainer.serializationCtx.eventQrls),
resources: Array.from(ssrContainer.serializationCtx.$resources$),
}
: {
Expand Down
6 changes: 5 additions & 1 deletion scripts/submodule-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ async function submoduleCoreProduction(config: BuildConfig, code: string, outPat
ecma: 2020,
preamble: getBanner('@qwik.dev/core', config.distVersion),
},
mangle: false,
mangle: {
properties: {
regex: '^\\$.+\\$$',
},
},
});
code = result.code!;

Expand Down
Loading