Skip to content

Commit

Permalink
perf(@angular-devkit/build-angular): start SSR dependencies optimizat…
Browse files Browse the repository at this point in the history
…ion before the first request

Vite will only start dependency optimization of SSR modules when the first request comes in.

In some cases, this causes a long waiting time. To mitigate this, we call `ssrLoadModule` to initiate this process before the first request.

(cherry picked from commit 1739924)
  • Loading branch information
alan-agius4 committed Nov 5, 2023
1 parent 23a722b commit 59c22aa
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,20 @@ export async function* serveWithVite(
);

server = await createServer(serverConfiguration);

await server.listen();

if (browserOptions.ssr) {
/**
* Vite will only start dependency optimization of SSR modules when the first request comes in.
* In some cases, this causes a long waiting time. To mitigate this, we call `ssrLoadModule` to
* initiate this process before the first request.
*
* NOTE: This will intentionally fail from the unknown module, but currently there is no other way
* to initiate the SSR dep optimizer.
*/
void server.ssrLoadModule('<deps-caller>').catch(() => {});
}

const urls = server.resolvedUrls;
if (urls && (urls.local.length || urls.network.length)) {
serverUrl = new URL(urls.local[0] ?? urls.network[0]);
Expand Down

0 comments on commit 59c22aa

Please sign in to comment.