diff --git a/packages/qwik/src/core/client/dom-container.ts b/packages/qwik/src/core/client/dom-container.ts index f37fdbb7291..b37d866d08f 100644 --- a/packages/qwik/src/core/client/dom-container.ts +++ b/packages/qwik/src/core/client/dom-container.ts @@ -372,7 +372,7 @@ export class DomContainer extends _SharedContainer implements IClientContainer { containerAttributes[attr.name] = attr.value; } } - this.$serverData$ = { containerAttributes }; + this.serverData = { containerAttributes }; } /** diff --git a/packages/qwik/src/core/client/dom-render.ts b/packages/qwik/src/core/client/dom-render.ts index 890589931c8..febbeaf8616 100644 --- a/packages/qwik/src/core/client/dom-render.ts +++ b/packages/qwik/src/core/client/dom-render.ts @@ -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); diff --git a/packages/qwik/src/core/qwik.core.api.md b/packages/qwik/src/core/qwik.core.api.md index 2df8dbce463..af0e8bd9665 100644 --- a/packages/qwik/src/core/qwik.core.api.md +++ b/packages/qwik/src/core/qwik.core.api.md @@ -870,8 +870,6 @@ export abstract class _SharedContainer implements Container { // (undocumented) readonly $scheduler$: Scheduler; // (undocumented) - $serverData$: Record; - // (undocumented) readonly $storeProxyMap$: ObjToProxyMap; // (undocumented) readonly $version$: string; @@ -901,6 +899,8 @@ export abstract class _SharedContainer implements Container { }; } | null, symbolToChunkResolver: SymbolToChunkResolver, writer?: StreamWriter, prepVNodeData?: (vNode: any) => void): SerializationContext; // (undocumented) + serverData: Record; + // (undocumented) abstract setContext(host: HostElement, context: ContextId, value: T): void; // (undocumented) abstract setHostProp(host: HostElement, name: string, value: T): void; diff --git a/packages/qwik/src/core/reactive-primitives/utils.ts b/packages/qwik/src/core/reactive-primitives/utils.ts index fe898ce337c..613276312aa 100644 --- a/packages/qwik/src/core/reactive-primitives/utils.ts +++ b/packages/qwik/src/core/reactive-primitives/utils.ts @@ -75,7 +75,7 @@ export const addQrlToSerializationCtx = ( qrl = container.getHostProp(effect as ISsrNode, OnRenderProp); } if (qrl) { - (container as SSRContainer).serializationCtx.$eventQrls$.add(qrl); + (container as SSRContainer).serializationCtx.eventQrls.add(qrl); } } }; diff --git a/packages/qwik/src/core/shared/shared-container.ts b/packages/qwik/src/core/shared/shared-container.ts index 04cbaf8feb4..b06f3d6ce2e 100644 --- a/packages/qwik/src/core/shared/shared-container.ts +++ b/packages/qwik/src/core/shared/shared-container.ts @@ -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; + serverData: Record; $currentUniqueId$ = 0; $instanceHash$: string | null = null; $buildBase$: string | null = null; @@ -29,7 +29,7 @@ export abstract class _SharedContainer implements Container { serverData: Record, locale: string ) { - this.$serverData$ = serverData; + this.serverData = serverData; this.$locale$ = locale; this.$version$ = version; this.$storeProxyMap$ = new WeakMap(); diff --git a/packages/qwik/src/core/shared/shared-serialization.ts b/packages/qwik/src/core/shared/shared-serialization.ts index 3909d563550..552bf0e42b3 100644 --- a/packages/qwik/src/core/shared/shared-serialization.ts +++ b/packages/qwik/src/core/shared/shared-serialization.ts @@ -621,7 +621,7 @@ type SeenRef = { let isDomRef = (obj: unknown): obj is DomRef => false; export interface SerializationContext { - $serialize$: () => void; + serialize: () => void; $symbolToChunkResolver$: SymbolToChunkResolver; @@ -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. @@ -660,7 +660,7 @@ export interface SerializationContext { $seen$: (obj: unknown, parent: unknown | null, index: number) => void; - $roots$: unknown[]; + roots: unknown[]; $pathMap$: Map; $addSyncFn$($funcStr$: string | null, argsCount: number, fn: Function): number; @@ -671,7 +671,7 @@ export interface SerializationContext { $writer$: StreamWriter; $syncFns$: string[]; - $eventQrls$: Set; + eventQrls: Set; $eventNames$: Set; $resources$: Set>; $renderSymbols$: Set; @@ -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; @@ -771,20 +771,20 @@ export const createSerializationContext = ( ) as (obj: unknown) => obj is DomRef; return { - async $serialize$(): Promise { + async serialize(): Promise { 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) => { @@ -809,7 +809,7 @@ export const createSerializationContext = ( return id; }, $writer$: writer, - $eventQrls$: new Set(), + eventQrls: new Set(), $eventNames$: new Set(), $resources$: new Set>(), $renderSymbols$: new Set(), @@ -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; } @@ -879,8 +879,15 @@ class PromiseResult { * - Therefore root indexes need to be doubled to get the actual index. */ async function serialize(serializationContext: SerializationContext): Promise { - 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; @@ -930,7 +937,7 @@ async function serialize(serializationContext: SerializationContext): Promise { preloadQrls.add(qrl); - serializationContext.$addRoot$(qrl, null); + serializationContext.addRoot(qrl, null); }; const outputRootRef = (value: unknown, elseCallback: () => void) => { @@ -964,7 +971,7 @@ async function serialize(serializationContext: SerializationContext): Promise 0) { @@ -1488,9 +1495,9 @@ export async function _serialize(data: unknown[]): Promise { ); for (const root of data) { - serializationContext.$addRoot$(root); + serializationContext.addRoot(root); } - await serializationContext.$serialize$(); + await serializationContext.serialize(); return serializationContext.$writer$.toString(); } diff --git a/packages/qwik/src/core/shared/shared-serialization.unit.ts b/packages/qwik/src/core/shared/shared-serialization.unit.ts index bf3b6822f0b..c4e2d467ab6 100644 --- a/packages/qwik/src/core/shared/shared-serialization.unit.ts +++ b/packages/qwik/src/core/shared/shared-serialization.unit.ts @@ -1064,9 +1064,9 @@ async function serialize(...roots: any[]): Promise { 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); diff --git a/packages/qwik/src/core/shared/types.ts b/packages/qwik/src/core/shared/types.ts index 18b9f67b85d..89298140278 100644 --- a/packages/qwik/src/core/shared/types.ts +++ b/packages/qwik/src/core/shared/types.ts @@ -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; + readonly serverData: Record; $currentUniqueId$: number; $buildBase$: string | null; diff --git a/packages/qwik/src/core/ssr/ssr-render-jsx.ts b/packages/qwik/src/core/ssr/ssr-render-jsx.ts index 51829a41093..3a415c45a85 100644 --- a/packages/qwik/src/core/ssr/ssr-render-jsx.ts +++ b/packages/qwik/src/core/ssr/ssr-render-jsx.ts @@ -484,7 +484,7 @@ function addQwikEventToSerializationContext( const eventName = getEventNameFromJsxEvent(key); if (eventName) { serializationCtx.$eventNames$.add(eventName); - serializationCtx.$eventQrls$.add(qrl); + serializationCtx.eventQrls.add(qrl); } } diff --git a/packages/qwik/src/core/use/use-env-data.ts b/packages/qwik/src/core/use/use-env-data.ts index 32d14476857..8ef40569ad1 100644 --- a/packages/qwik/src/core/use/use-env-data.ts +++ b/packages/qwik/src/core/use/use-env-data.ts @@ -9,5 +9,5 @@ export function useServerData(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; } diff --git a/packages/qwik/src/server/ssr-container.ts b/packages/qwik/src/server/ssr-container.ts index edbaabe6f95..9cf612e23b4 100644 --- a/packages/qwik/src/server/ssr-container.ts +++ b/packages/qwik/src/server/ssr-container.ts @@ -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( (acc, [key, value]) => { @@ -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++; } } @@ -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 { @@ -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']); @@ -825,11 +825,11 @@ class SSRContainer extends _SharedContainer implements ISSRContainer { } private emitStateData(): ValueOrPromise { - 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(); }); } @@ -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) @@ -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() { diff --git a/packages/qwik/src/server/ssr-render.ts b/packages/qwik/src/server/ssr-render.ts index c21aba04121..2c58063cae2 100644 --- a/packages/qwik/src/server/ssr-render.ts +++ b/packages/qwik/src/server/ssr-render.ts @@ -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$), } : { diff --git a/scripts/submodule-core.ts b/scripts/submodule-core.ts index fb9bbc8dbf6..7dc8361a129 100644 --- a/scripts/submodule-core.ts +++ b/scripts/submodule-core.ts @@ -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!;