Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/new-kangaroos-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Handle hash links with non-ASCII characters when prerendering
5 changes: 4 additions & 1 deletion packages/kit/src/core/prerender/fixtures/ids/input.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<h2 id="before">before</h2>
<span data-x='"\\"'>backslash</span>
<h2 id="after">after</h2>
<h2 id="after">after</h2>
<h2 id="encöded">
<a href="#encöded">encöded</a>
</h2>
4 changes: 2 additions & 2 deletions packages/kit/src/core/prerender/fixtures/ids/output.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"hrefs": [],
"ids": ["before", "after"]
"hrefs": ["#encöded"],
"ids": ["before", "after", "encöded"]
}
10 changes: 6 additions & 4 deletions packages/kit/src/core/prerender/prerender.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export async function prerender() {
config.prerender.handleMissingId,
({ path, id, referrers }) => {
return (
`The following pages contain links to ${path}#${id}, but no element with id="${id}" exists on ${path}:` +
`The following pages contain links to ${path}#${id}, but no element with id="${id}" exists on ${path} - see the \`handleMissingId\` option in https://kit.svelte.dev/docs/configuration#prerender for more info:` +
referrers.map((l) => `\n - ${l}`).join('')
);
}
Expand Down Expand Up @@ -262,11 +262,13 @@ export async function prerender() {
}

if (hash) {
if (!expected_hashlinks.has(pathname + hash)) {
expected_hashlinks.set(pathname + hash, new Set());
const key = decodeURI(pathname + hash);

if (!expected_hashlinks.has(key)) {
expected_hashlinks.set(key, new Set());
}

/** @type {Set<string>} */ (expected_hashlinks.get(pathname + hash)).add(decoded);
/** @type {Set<string>} */ (expected_hashlinks.get(key)).add(decoded);
}

enqueue(decoded, decodeURI(pathname), pathname);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h2 id="encöded">
<a href="#encöded">encöded</a>
</h2>