Skip to content

Commit 9c5c198

Browse files
committed
perf(core): read client manifest only if and when needed
1 parent 95204ba commit 9c5c198

File tree

1 file changed

+29
-22
lines changed
  • packages/qwik/src/optimizer/src/plugins

1 file changed

+29
-22
lines changed

packages/qwik/src/optimizer/src/plugins/plugin.ts

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -285,27 +285,6 @@ export function createQwikPlugin(optimizerOptions: OptimizerOptions = {}) {
285285
if (updatedOpts.manifestInput) {
286286
opts.manifestInput = getValidManifest(updatedOpts.manifestInput) || null;
287287
}
288-
if (
289-
!opts.manifestInput &&
290-
opts.target === 'ssr' &&
291-
opts.buildMode === 'production' &&
292-
maybeFs
293-
) {
294-
let clientManifestPath = resolvePath(opts.clientOutDir, Q_MANIFEST_FILENAME);
295-
if (!(await maybeFs.promises.stat(clientManifestPath).catch(() => false))) {
296-
clientManifestPath = resolvePath(opts.rootDir, CLIENT_OUT_DIR, Q_MANIFEST_FILENAME);
297-
}
298-
try {
299-
const clientManifestStr = await maybeFs.promises.readFile(clientManifestPath, 'utf-8');
300-
opts.manifestInput = getValidManifest(JSON.parse(clientManifestStr)) || null;
301-
// eslint-disable-next-line no-console
302-
console.info('Read client manifest from', clientManifestPath);
303-
} catch (e) {
304-
console.warn(
305-
`could not read Qwik client manifest ${clientManifestPath}, ignoring. Make sure you provide it to the SSR renderer. (${e})`
306-
);
307-
}
308-
}
309288

310289
if (typeof updatedOpts.transformedModuleOutput === 'function') {
311290
opts.transformedModuleOutput = updatedOpts.transformedModuleOutput;
@@ -944,6 +923,34 @@ export const isDev = ${JSON.stringify(isDev)};
944923
}
945924

946925
async function getQwikServerManifestModule(isServer: boolean) {
926+
if (
927+
!opts.manifestInput &&
928+
opts.target === 'ssr' &&
929+
opts.buildMode === 'production' &&
930+
maybeFs
931+
) {
932+
const path = getPath();
933+
let clientManifestPath = path.resolve(opts.clientOutDir, Q_MANIFEST_FILENAME);
934+
if (!(await maybeFs.promises.stat(clientManifestPath).catch(() => false))) {
935+
clientManifestPath = path.resolve(opts.rootDir, CLIENT_OUT_DIR, Q_MANIFEST_FILENAME);
936+
}
937+
try {
938+
const clientManifestStr = await maybeFs.promises.readFile(clientManifestPath, 'utf-8');
939+
opts.manifestInput = getValidManifest(JSON.parse(clientManifestStr)) || null;
940+
// eslint-disable-next-line no-console
941+
console.info('Read client manifest from', clientManifestPath);
942+
} catch (e) {
943+
console.warn(
944+
`\n==========\n` +
945+
`Could not read Qwik client manifest ${clientManifestPath}.\n` +
946+
`Make sure you provide it to the SSR renderer via the \`manifest\` argument, or define it in \`globalThis.__QWIK_MANIFEST__\` before the server bundle is loaded, or embed it in the server bundle by replacing \`globalThis.__QWIK_MANIFEST__\`.\n` +
947+
`Without the manifest, the SSR renderer will not be able to generate event handlers.\n` +
948+
`(${e})\n` +
949+
`==========\n`
950+
);
951+
}
952+
}
953+
947954
const manifest = isServer ? opts.manifestInput : null;
948955
let serverManifest: ServerQwikManifest | null = null;
949956
if (manifest?.manifestHash) {
@@ -959,7 +966,7 @@ export const isDev = ${JSON.stringify(isDev)};
959966
};
960967
}
961968
return `// @qwik-client-manifest
962-
export const manifest = ${JSON.stringify(serverManifest)};\n`;
969+
export const manifest = ${serverManifest ? JSON.stringify(serverManifest) : 'globalThis.__QWIK_MANIFEST__'};\n`;
963970
}
964971

965972
function setSourceMapSupport(sourcemap: boolean) {

0 commit comments

Comments
 (0)