From e8e5ef3994e2e1092b265eb85a2fe287a8985cff Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 10 Feb 2022 16:37:51 -0500 Subject: [PATCH 1/5] prerender external links --- packages/kit/src/core/adapt/prerender/crawl.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/kit/src/core/adapt/prerender/crawl.js b/packages/kit/src/core/adapt/prerender/crawl.js index 8cf584cf77a5..75da216813da 100644 --- a/packages/kit/src/core/adapt/prerender/crawl.js +++ b/packages/kit/src/core/adapt/prerender/crawl.js @@ -8,8 +8,6 @@ const TAG_OPEN = /[a-zA-Z]/; const TAG_CHAR = /[a-zA-Z0-9]/; const ATTRIBUTE_NAME = /[^\t\n\f />"'=]/; -const EXTERNAL = /\bexternal\b/; - const WHITESPACE = /[\s\n\r]/; /** @param {string} html */ @@ -183,7 +181,7 @@ export function crawl(html) { i += 1; } - if (href && !EXTERNAL.test(rel)) { + if (href) { hrefs.push(href); } } From a8ccaec034a2eb1efbc88eba46d790fe18e32e6d Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 15 Feb 2022 11:21:32 -0500 Subject: [PATCH 2/5] update tests --- .../adapt/prerender/fixtures/ignore-rel-external/output.json | 1 - .../{ignore-rel-external => include-rel-external}/input.html | 0 .../adapt/prerender/fixtures/include-rel-external/output.json | 1 + 3 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 packages/kit/src/core/adapt/prerender/fixtures/ignore-rel-external/output.json rename packages/kit/src/core/adapt/prerender/fixtures/{ignore-rel-external => include-rel-external}/input.html (100%) create mode 100644 packages/kit/src/core/adapt/prerender/fixtures/include-rel-external/output.json diff --git a/packages/kit/src/core/adapt/prerender/fixtures/ignore-rel-external/output.json b/packages/kit/src/core/adapt/prerender/fixtures/ignore-rel-external/output.json deleted file mode 100644 index 75f29a134a4f..000000000000 --- a/packages/kit/src/core/adapt/prerender/fixtures/ignore-rel-external/output.json +++ /dev/null @@ -1 +0,0 @@ -["/styles.css", "/favicon.png", "https://external.com"] diff --git a/packages/kit/src/core/adapt/prerender/fixtures/ignore-rel-external/input.html b/packages/kit/src/core/adapt/prerender/fixtures/include-rel-external/input.html similarity index 100% rename from packages/kit/src/core/adapt/prerender/fixtures/ignore-rel-external/input.html rename to packages/kit/src/core/adapt/prerender/fixtures/include-rel-external/input.html diff --git a/packages/kit/src/core/adapt/prerender/fixtures/include-rel-external/output.json b/packages/kit/src/core/adapt/prerender/fixtures/include-rel-external/output.json new file mode 100644 index 000000000000..50b8dceed0d6 --- /dev/null +++ b/packages/kit/src/core/adapt/prerender/fixtures/include-rel-external/output.json @@ -0,0 +1 @@ +["/styles.css", "/favicon.png", "https://external.com", "/wheee"] From 4eb89b7ef11520eea91e0103b1b5268810c63973 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 15 Feb 2022 11:24:27 -0500 Subject: [PATCH 3/5] changeset --- .changeset/tall-berries-guess.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tall-berries-guess.md diff --git a/.changeset/tall-berries-guess.md b/.changeset/tall-berries-guess.md new file mode 100644 index 000000000000..50abe8cfd22c --- /dev/null +++ b/.changeset/tall-berries-guess.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +[breaking] Crawl rel="external" links when prerendering From 7f4a9673759341cfc9736640aa6ce641fd266a98 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 15 Feb 2022 11:28:04 -0500 Subject: [PATCH 4/5] lint --- packages/kit/src/core/adapt/prerender/crawl.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/kit/src/core/adapt/prerender/crawl.js b/packages/kit/src/core/adapt/prerender/crawl.js index 75da216813da..8bcf72ac4a18 100644 --- a/packages/kit/src/core/adapt/prerender/crawl.js +++ b/packages/kit/src/core/adapt/prerender/crawl.js @@ -86,7 +86,6 @@ export function crawl(html) { } } - let rel = ''; let href = ''; while (i < html.length) { @@ -147,9 +146,7 @@ export function crawl(html) { i -= 1; } - if (name === 'rel') { - rel = value; - } else if (name === 'href') { + if (name === 'href') { href = value; } else if (name === 'src') { hrefs.push(value); From 6a7f51b20e2a4ff3c256e312cff9b9cfabc2625a Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 15 Feb 2022 11:43:04 -0500 Subject: [PATCH 5/5] add note about prerendering --- documentation/docs/07-a-options.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/documentation/docs/07-a-options.md b/documentation/docs/07-a-options.md index b81d5afc7daf..356dc05fb971 100644 --- a/documentation/docs/07-a-options.md +++ b/documentation/docs/07-a-options.md @@ -43,3 +43,5 @@ Adding a `rel=external` attribute to a link... ``` ...will trigger a browser navigation when the link is clicked. + +> SvelteKit does not exclude root-relative external links from prerendering, which will cause 404s if these URLs are intended to be served by a separate app. Use a custom [`prerender.onError`](/docs/configuration#prerender) handler if you need to ignore them.