Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support sveltekit apps on non-http protocols #13289

Closed
wants to merge 2 commits into from
Closed
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/dirty-impalas-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Added support for loading sveltekit apps on non-http protocols (eg: the `about:` protocol used on iframes that are populated via srcdoc)
5 changes: 5 additions & 0 deletions packages/kit/src/runtime/client/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@ export function is_external_url(url, base, hash_routing) {
return false;
}

// be lenient if serving from an iframe via srcdoc
if (url.protocol === 'about:') {
return false;
}

// be lenient if serving from filesystem
if (url.protocol === 'file:' && url.pathname.replace(/\/[^/]+\.html?$/, '') === base) {
return false;
Expand Down
3 changes: 2 additions & 1 deletion packages/kit/src/runtime/server/page/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ export async function render_response({
}
} else if (options.hash_routing) {
// we have to assume that we're in the right place
base_expression = "new URL('.', location).pathname.slice(0, -1)";
// if we are not on an http protocol (eg: about: protocol on iframes) we default to an empty string. Otherwise an error would be thrown by the URL constructor
base_expression = `location.protocol.slice(0, 4) === "http" ? new URL(${s(base)}, location).pathname.slice(0, -1) : ""`;
}
}

Expand Down
Loading