Skip to content
Merged
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
18 changes: 17 additions & 1 deletion packages/qwik/src/optimizer/src/plugins/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,16 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any {
const renderToStringOpts: RenderToStringOptions = {
url: url.href,
debug: true,
manifest: isClientDevOnly ? undefined : manifest,
snapshot: !isClientDevOnly,
manifest: isClientDevOnly ? undefined : manifest,
symbolMapper: isClientDevOnly
? undefined
: (symbolName, mapper) => {
if (mapper) {
const hash = getSymbolHash(symbolName);
return mapper[hash];
}
},
prefetchStrategy: null,
};

Expand Down Expand Up @@ -484,6 +492,14 @@ export function render(document, rootNode) {
}`;
}

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

const VITE_CLIENT_MODULE = `@builder.io/qwik/vite-client`;
const VITE_DEV_CLIENT_QS = `qwik-vite-dev-client`;
const CLIENT_DEV_INPUT = 'entry.dev.tsx';
Expand Down
8 changes: 8 additions & 0 deletions packages/qwik/src/optimizer/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,14 @@ export interface QwikManifest {

export type SymbolMapper = Record<string, [symbol: string, chunk: string]>;

/**
* @alpha
*/
export type SymbolMapperFn = (
symbolName: string,
mapper: SymbolMapper | undefined
) => [symbol: string, chunk: string] | undefined;

/**
* @alpha
*/
Expand Down
22 changes: 14 additions & 8 deletions packages/qwik/src/server/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ function createPlatform(
doc.location.href = normalizeUrl(opts.url).href;
}

const mapperFn = opts.symbolMapper
? opts.symbolMapper
: (symbolName: string) => {
if (mapper) {
const hash = getSymbolHash(symbolName);
const result = mapper[hash];
if (!result) {
logError('Cannot resolved symbol', symbolName, 'in', mapper);
}
return result;
}
};

const serverPlatform: CorePlatform = {
isServer: true,
async importSymbol(_element, qrl, symbolName) {
Expand Down Expand Up @@ -48,14 +61,7 @@ function createPlatform(
});
},
chunkForSymbol(symbolName: string) {
if (mapper) {
const hash = getSymbolHash(symbolName);
const result = mapper[hash];
if (!result) {
logError('Cannot resolved symbol', symbolName, 'in', mapper);
}
return result;
}
return mapperFn(symbolName, mapper);
},
};
return serverPlatform;
Expand Down
6 changes: 4 additions & 2 deletions packages/qwik/src/server/prefetch-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ function getAutoPrefetch(
for (const obj of stateObjs) {
if (isQrl(obj)) {
const qrlSymbolName = obj.getHash();
// TODO, imporove symbol to bundle lookup
addBundle(manifest, urls, prefetchResources, buildBase, mapper[qrlSymbolName][0]);
const resolvedSymbol = mapper[qrlSymbolName];
if (resolvedSymbol) {
addBundle(manifest, urls, prefetchResources, buildBase, resolvedSymbol[0]);
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions packages/qwik/src/server/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { SnapshotResult } from '../core/object/store';
import type { QwikManifest, QwikBundle, QwikSymbol, GlobalInjections } from '../optimizer/src';
import type { SymbolMapperFn } from '../optimizer/src/types';

/**
* Partial Document used by Qwik Framework.
Expand All @@ -14,6 +15,7 @@ export interface QwikDocument extends Document {}
*/
export interface SerializeDocumentOptions {
manifest?: QwikManifest;
symbolMapper?: SymbolMapperFn;
url?: URL | string;
html?: string;
debug?: boolean;
Expand Down
4 changes: 2 additions & 2 deletions starters/apps/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"build.client": "vite build",
"build.ssr": "vite build --ssr src/entry.server.tsx",
"dev": "vite",
"dev.ssr": "vite --mode ssr",
"dev.debug": "node --inspect-brk node_modules/vite/bin/vite.js",
"dev.ssr": "node --inspect node_modules/vite/bin/vite.js --mode ssr",
"dev.debug": "node --inspect-brk node_modules/vite/bin/vite.js --mode ssr",
"start": "npm run dev",
"typecheck": "tsc --noEmit"
},
Expand Down