Skip to content

Commit

Permalink
chore: should load html template while server preparing
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerHT committed Dec 17, 2024
1 parent bb97b94 commit 3ffebb3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/server/core/src/adapters/node/plugins/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ export async function getHtmlTemplates(pwd: string, routes: ServerRoute[]) {
export function injectTemplates(
pwd: string,
routes?: ServerRoute[],
htmlTemplatePromise?: ReturnType<typeof getHtmlTemplates>,
): Middleware<ServerEnv> {
return async (c, next) => {
if (routes && !c.get('templates')) {
const templates = await getHtmlTemplates(pwd, routes);
const templates = await (htmlTemplatePromise ||
getHtmlTemplates(pwd, routes));
c.set('templates', templates);
}

Expand Down Expand Up @@ -148,9 +150,13 @@ export const injectResourcePlugin = (): ServerPlugin => ({
async prepare() {
const { middlewares, routes, distDirectory: pwd } = api.useAppContext();

let htmlTemplatePromise:
| ReturnType<typeof getHtmlTemplates>
| undefined;
// In Production, should warmup server bundles on prepare.
if (isProd()) {
getServerManifest(pwd, routes || [], console);
htmlTemplatePromise = getHtmlTemplates(pwd, routes || []);
}

middlewares.push({
Expand All @@ -162,7 +168,7 @@ export const injectResourcePlugin = (): ServerPlugin => ({
middlewares.push({
name: 'inject-html',

handler: injectTemplates(pwd, routes),
handler: injectTemplates(pwd, routes, htmlTemplatePromise),
});
},
};
Expand Down

0 comments on commit 3ffebb3

Please sign in to comment.