From 10a620bebb05c427f949bda552571b59aa88bb3a Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 15 Dec 2022 12:57:32 +0100 Subject: [PATCH 1/6] add warning when skipping route due to length limit --- src/prerender.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/prerender.ts b/src/prerender.ts index 8f9713dd14..199b95eefb 100644 --- a/src/prerender.ts +++ b/src/prerender.ts @@ -76,11 +76,19 @@ export async function prerender(nitro: Nitro) { // Start prerendering const generatedRoutes = new Set(); + const displayedLengthWarns = new Set(); const canPrerender = (route: string = "/") => { if (generatedRoutes.has(route)) { return false; } if (route.length > 250) { + if (!displayedLengthWarns.has(route)) { + displayedLengthWarns.add(route); + const _route = route.slice(0, 60); + nitro.logger.warn( + `Skipping prerender of route "${_route}..." since it exceeds 250 characters.` + ); + } return false; } for (const ignore of nitro.options.prerender.ignore) { From f079019b1ad9edf6e05404e13101a18032aed786 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 15 Dec 2022 13:04:52 +0100 Subject: [PATCH 2/6] fix(prerender): check each segment length is less than 255 chars --- src/prerender.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/prerender.ts b/src/prerender.ts index 199b95eefb..63e9d85b86 100644 --- a/src/prerender.ts +++ b/src/prerender.ts @@ -78,27 +78,36 @@ export async function prerender(nitro: Nitro) { const generatedRoutes = new Set(); const displayedLengthWarns = new Set(); const canPrerender = (route: string = "/") => { + // Skip if route is already generated if (generatedRoutes.has(route)) { return false; } - if (route.length > 250) { + + // Ensure length is not too long for filesystem + const segments = route.split("/"); + if (segments.some((s) => s.length > 255)) { if (!displayedLengthWarns.has(route)) { displayedLengthWarns.add(route); const _route = route.slice(0, 60); nitro.logger.warn( - `Skipping prerender of route "${_route}..." since it exceeds 250 characters.` + `Skipping prerender of route "${_route}..." since it exceeds 255 characters in one of the segments and can cause filesystem issues.` ); } return false; } + + // Check for explicitly ignored routes for (const ignore of nitro.options.prerender.ignore) { if (route.startsWith(ignore)) { return false; } } + + // Check for route rules explicitly disabling prerender if (_getRouteRules(route).prerender === false) { return false; } + return true; }; From c95aa5413fe90409c91c2f96cc6c628edb7e5d20 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 15 Dec 2022 13:09:10 +0100 Subject: [PATCH 3/6] improve warning --- src/prerender.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/prerender.ts b/src/prerender.ts index 63e9d85b86..f778e1087f 100644 --- a/src/prerender.ts +++ b/src/prerender.ts @@ -88,9 +88,9 @@ export async function prerender(nitro: Nitro) { if (segments.some((s) => s.length > 255)) { if (!displayedLengthWarns.has(route)) { displayedLengthWarns.add(route); - const _route = route.slice(0, 60); + const _route = route.slice(0, 60) + "..."; nitro.logger.warn( - `Skipping prerender of route "${_route}..." since it exceeds 255 characters in one of the segments and can cause filesystem issues.` + `Skipping prerender of the route "${_route}" since it exceeds the 255-character limit in one of the path segments and can cause filesystem issues.` ); } return false; From 61649ed21832ead19c3b3d2fa63c0ff89c6d77ca Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 15 Dec 2022 13:21:32 +0100 Subject: [PATCH 4/6] improve warning and add apfs soft limit --- src/prerender.ts | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/prerender.ts b/src/prerender.ts index f778e1087f..a1d174b1e6 100644 --- a/src/prerender.ts +++ b/src/prerender.ts @@ -84,16 +84,27 @@ export async function prerender(nitro: Nitro) { } // Ensure length is not too long for filesystem - const segments = route.split("/"); - if (segments.some((s) => s.length > 255)) { - if (!displayedLengthWarns.has(route)) { - displayedLengthWarns.add(route); - const _route = route.slice(0, 60) + "..."; + // 1024 is the max path length on APFS (undocumented) + const FS_MAX_PATH = 1024 - (nitro.options.output.publicDir.length + 10); + // https://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits + const FS_MAX_SEGMENT = 255; + if ( + (route.length >= FS_MAX_PATH || + route.split("/").some((s) => s.length > FS_MAX_SEGMENT)) && + !displayedLengthWarns.has(route) + ) { + displayedLengthWarns.add(route); + const _route = route.slice(0, 60) + "..."; + if (route.length >= FS_MAX_PATH) { nitro.logger.warn( - `Skipping prerender of the route "${_route}" since it exceeds the 255-character limit in one of the path segments and can cause filesystem issues.` + `Prerendering long route "${_route}" (${route.length}) can cause filesystem issues since it exceeds ${FS_MAX_PATH}-character limit and can cause filesystem issues.` ); + } else { + nitro.logger.warn( + `Skipping prerender of the route "${_route}" since it exceeds the ${FS_MAX_SEGMENT}-character limit in one of the path segments and can cause filesystem issues.` + ); + return false; } - return false; } // Check for explicitly ignored routes From f2601db87430119cf1954b0b39459fe8407ee9e8 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 15 Dec 2022 13:29:32 +0100 Subject: [PATCH 5/6] clarify message little bit more --- src/prerender.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/prerender.ts b/src/prerender.ts index a1d174b1e6..c91883750d 100644 --- a/src/prerender.ts +++ b/src/prerender.ts @@ -84,20 +84,23 @@ export async function prerender(nitro: Nitro) { } // Ensure length is not too long for filesystem - // 1024 is the max path length on APFS (undocumented) - const FS_MAX_PATH = 1024 - (nitro.options.output.publicDir.length + 10); // https://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits const FS_MAX_SEGMENT = 255; + // 1024 is the max path length on APFS (undocumented) + const FS_MAX_PATH = 1024; + const FS_MAX_PATH_PUBLIC_HTML = + FS_MAX_PATH - (nitro.options.output.publicDir.length + 10); + if ( - (route.length >= FS_MAX_PATH || + (route.length >= FS_MAX_PATH_PUBLIC_HTML || route.split("/").some((s) => s.length > FS_MAX_SEGMENT)) && !displayedLengthWarns.has(route) ) { displayedLengthWarns.add(route); const _route = route.slice(0, 60) + "..."; - if (route.length >= FS_MAX_PATH) { + if (route.length >= FS_MAX_PATH_PUBLIC_HTML) { nitro.logger.warn( - `Prerendering long route "${_route}" (${route.length}) can cause filesystem issues since it exceeds ${FS_MAX_PATH}-character limit and can cause filesystem issues.` + `Prerendering long route "${_route}" (${route.length}) can cause filesystem issues since it exceeds ${FS_MAX_PATH_PUBLIC_HTML}-character limit when writing to ${nitro.options.output.publicDir} and can cause filesystem issues.` ); } else { nitro.logger.warn( From 0600b246804c7a86c891d3cf7aa1cf17b24f7d8b Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 15 Dec 2022 13:33:28 +0100 Subject: [PATCH 6/6] update warn --- src/prerender.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/prerender.ts b/src/prerender.ts index c91883750d..2b45322805 100644 --- a/src/prerender.ts +++ b/src/prerender.ts @@ -100,7 +100,7 @@ export async function prerender(nitro: Nitro) { const _route = route.slice(0, 60) + "..."; if (route.length >= FS_MAX_PATH_PUBLIC_HTML) { nitro.logger.warn( - `Prerendering long route "${_route}" (${route.length}) can cause filesystem issues since it exceeds ${FS_MAX_PATH_PUBLIC_HTML}-character limit when writing to ${nitro.options.output.publicDir} and can cause filesystem issues.` + `Prerendering long route "${_route}" (${route.length}) can cause filesystem issues since it exceeds ${FS_MAX_PATH_PUBLIC_HTML}-character limit when writing to \`${nitro.options.output.publicDir}\`.` ); } else { nitro.logger.warn(