Skip to content

Commit 07e2145

Browse files
committed
perf(core): read client manifest only if and when needed
1 parent 6019cbc commit 07e2145

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
@@ -280,27 +280,6 @@ export function createQwikPlugin(optimizerOptions: OptimizerOptions = {}) {
280280
if (updatedOpts.manifestInput) {
281281
opts.manifestInput = getValidManifest(updatedOpts.manifestInput) || null;
282282
}
283-
if (
284-
!opts.manifestInput &&
285-
opts.target === 'ssr' &&
286-
opts.buildMode === 'production' &&
287-
maybeFs
288-
) {
289-
let clientManifestPath = resolvePath(opts.clientOutDir, Q_MANIFEST_FILENAME);
290-
if (!(await maybeFs.promises.stat(clientManifestPath).catch(() => false))) {
291-
clientManifestPath = resolvePath(opts.rootDir, CLIENT_OUT_DIR, Q_MANIFEST_FILENAME);
292-
}
293-
try {
294-
const clientManifestStr = await maybeFs.promises.readFile(clientManifestPath, 'utf-8');
295-
opts.manifestInput = getValidManifest(JSON.parse(clientManifestStr)) || null;
296-
// eslint-disable-next-line no-console
297-
console.info('Read client manifest from', clientManifestPath);
298-
} catch (e) {
299-
console.warn(
300-
`could not read Qwik client manifest ${clientManifestPath}, ignoring. Make sure you provide it to the SSR renderer. (${e})`
301-
);
302-
}
303-
}
304283

305284
if (typeof updatedOpts.transformedModuleOutput === 'function') {
306285
opts.transformedModuleOutput = updatedOpts.transformedModuleOutput;
@@ -939,6 +918,34 @@ export const isDev = ${JSON.stringify(isDev)};
939918
}
940919

941920
async function getQwikServerManifestModule(isServer: boolean) {
921+
if (
922+
!opts.manifestInput &&
923+
opts.target === 'ssr' &&
924+
opts.buildMode === 'production' &&
925+
maybeFs
926+
) {
927+
const path = getPath();
928+
let clientManifestPath = path.resolve(opts.clientOutDir, Q_MANIFEST_FILENAME);
929+
if (!(await maybeFs.promises.stat(clientManifestPath).catch(() => false))) {
930+
clientManifestPath = path.resolve(opts.rootDir, CLIENT_OUT_DIR, Q_MANIFEST_FILENAME);
931+
}
932+
try {
933+
const clientManifestStr = await maybeFs.promises.readFile(clientManifestPath, 'utf-8');
934+
opts.manifestInput = getValidManifest(JSON.parse(clientManifestStr)) || null;
935+
// eslint-disable-next-line no-console
936+
console.info('Read client manifest from', clientManifestPath);
937+
} catch (e) {
938+
console.warn(
939+
`\n==========\n` +
940+
`Could not read Qwik client manifest ${clientManifestPath}.\n` +
941+
`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` +
942+
`Without the manifest, the SSR renderer will not be able to generate event handlers.\n` +
943+
`(${e})\n` +
944+
`==========\n`
945+
);
946+
}
947+
}
948+
942949
const manifest = isServer ? opts.manifestInput : null;
943950
let serverManifest: ServerQwikManifest | null = null;
944951
if (manifest?.manifestHash) {
@@ -954,7 +961,7 @@ export const isDev = ${JSON.stringify(isDev)};
954961
};
955962
}
956963
return `// @qwik-client-manifest
957-
export const manifest = ${JSON.stringify(serverManifest)};\n`;
964+
export const manifest = ${serverManifest ? JSON.stringify(serverManifest) : 'globalThis.__QWIK_MANIFEST__'};\n`;
958965
}
959966

960967
function setSourceMapSupport(sourcemap: boolean) {

0 commit comments

Comments
 (0)