From 63d5be06c7cf12a3d79638e8a143b54a421338fc Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Fri, 4 Aug 2023 21:41:48 +0200 Subject: [PATCH 1/3] fix(prerender): call `prerender:route` before freeing up memory --- src/prerender.ts | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/prerender.ts b/src/prerender.ts index 9522206d23..31ff78bc93 100644 --- a/src/prerender.ts +++ b/src/prerender.ts @@ -232,7 +232,13 @@ export async function prerender(nitro: Nitro) { } } - dataBuff = undefined; // Free memory + if (!_route.skip) { + await nitro.hooks.callHook("prerender:route", _route); + nitro.logger.log(formatPrerenderRoute(_route)); + } + + // Free memory + dataBuff = undefined; return _route; }; @@ -243,20 +249,7 @@ export async function prerender(nitro: Nitro) { : `Prerendering ${routes.size} routes` ); - async function processRoute(route: string) { - const _route = await generateRoute(route).catch( - (error) => ({ route, error }) as PrerenderGenerateRoute - ); - - if (!_route || _route.skip) { - return; - } - - await nitro.hooks.callHook("prerender:route", _route); - nitro.logger.log(formatPrerenderRoute(_route)); - } - - await runParallel(routes, processRoute, { + await runParallel(routes, generateRoute, { concurrency: nitro.options.prerender.concurrency, interval: nitro.options.prerender.interval, }); @@ -295,9 +288,11 @@ async function runParallel( } inputs.delete(route); - const task = new Promise((resolve) => - setTimeout(resolve, opts.interval) - ).then(() => cb(route)); + const task = new Promise((resolve) => setTimeout(resolve, opts.interval)) + .then(() => cb(route)) + .catch((error) => { + console.error(error); + }); tasks.add(task); return task.then(() => { From 4c0fed32d5f69228d7a51a5658604a742c776c43 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Fri, 4 Aug 2023 21:45:10 +0200 Subject: [PATCH 2/3] add hook for error short circut --- src/prerender.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/prerender.ts b/src/prerender.ts index 31ff78bc93..f3e25e48b3 100644 --- a/src/prerender.ts +++ b/src/prerender.ts @@ -208,6 +208,8 @@ export async function prerender(nitro: Nitro) { // Check if route skipped or has errors if (_route.skip || _route.error) { + await nitro.hooks.callHook("prerender:route", _route); + nitro.logger.log(formatPrerenderRoute(_route)); return _route; } From ec0631ae84c8db4f5200d4393b18db0861b9e358 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Fri, 4 Aug 2023 21:45:53 +0200 Subject: [PATCH 3/3] remove unnecessary check --- src/prerender.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/prerender.ts b/src/prerender.ts index f3e25e48b3..2a6e804dd7 100644 --- a/src/prerender.ts +++ b/src/prerender.ts @@ -234,10 +234,8 @@ export async function prerender(nitro: Nitro) { } } - if (!_route.skip) { - await nitro.hooks.callHook("prerender:route", _route); - nitro.logger.log(formatPrerenderRoute(_route)); - } + await nitro.hooks.callHook("prerender:route", _route); + nitro.logger.log(formatPrerenderRoute(_route)); // Free memory dataBuff = undefined;