-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Handle cases when location.protocol is about:
or data:
#13226
Comments
about:
or data:
about:
or data:
kit/packages/kit/src/runtime/server/page/render.js Lines 103 to 113 in 64c8e04
An ugly fix would be - `new URL(${s(base)}, location).pathname.slice(0, -1)`
+ `["about:", "data:"].includes(location.protocol) ? `${s(base)} : new URL(${s(base)}, location).pathname.slice(0, -1)`
- new URL('.', location).pathname.slice(0, -1)
+ ["about:", "data:"].includes(location.protocol) ? "" : new URL('.', location).pathname.slice(0, -1) |
You are welcome to open a pull request. Are there any other protocols we need to consider? Maybe we can create a set and search that. |
I think maybe |
Did some investigation and there seems to be two ways of embedding SvelteKit through HTML text: 1. iframe srcdoc="..."The document will have an embedded URL of 2. iframe src="data:text/html;charset=utf-8,..."The document will have an embedded URL of Overall, there's a number of changes we need to make to avoid the "invalid base URL" error when constructing a new URL object to improve embedding SvelteKit apps as HTML text.
kit/packages/kit/src/runtime/client/utils.js Lines 15 to 22 in 5b667e4
kit/packages/kit/src/runtime/client/utils.js Line 132 in 5b667e4
kit/packages/kit/src/runtime/client/client.js Line 1854 in 5b667e4
kit/packages/kit/src/runtime/client/client.js Line 2504 in 5b667e4
cc: @kran6a Also, when using a hash router, it's possible for the page to infinitely refresh due to the embedded URL pathname not passing any of the conditions below (#13287): kit/packages/kit/src/runtime/client/utils.js Lines 313 to 324 in 5b667e4
Fortunately, we can check if |
I applied this patch on my node_modules and it works for my use-case. There are no invalid base URL errors and no infinite reloads. One strange thing I noticed that also broke when migrating widgets from raw svelte (bundling to a single .js file then inlining it into an HTML shell) to sveltekit is that previously I injected some classes into the iframe from the host website via iframe_element.contentWindow.props = {some_class: Class}; //Class is a class definition, not an instance These classes use runes and this approach worked on svelte but reactivity broke after transitioning to sveltekit. diff --git a/node_modules/@sveltejs/kit/src/runtime/client/utils.js b/node_modules/@sveltejs/kit/src/runtime/client/utils.js
index 28a06d8..24b6ee7 100644
--- a/node_modules/@sveltejs/kit/src/runtime/client/utils.js
+++ b/node_modules/@sveltejs/kit/src/runtime/client/utils.js
@@ -311,6 +311,9 @@ export function is_external_url(url, base, hash_routing) {
}
if (hash_routing) {
+ if (url.protocol === "about:" || url.protocol === "data:"){
+ return false;
+ }
if (url.pathname === base + '/' || url.pathname === base + '/index.html') {
return false;
}
diff --git a/node_modules/@sveltejs/kit/src/runtime/server/page/render.js b/node_modules/@sveltejs/kit/src/runtime/server/page/render.js
index d8fbe32..82867e0 100644
--- a/node_modules/@sveltejs/kit/src/runtime/server/page/render.js
+++ b/node_modules/@sveltejs/kit/src/runtime/server/page/render.js
@@ -109,7 +109,7 @@ 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)";
+ base_expression = "location.protocol === 'about:' || location.protocol === 'data:' ? '' : new URL('.', location.protocol).pathname.slice(0, -1)";
}
}
|
Describe the problem
I am using svelte in several embedded webviews. I used to have to run a static file server before
bundleStrategy: 'inline'
became available yesterday.Normally (if we click this html file) the url will start with
file://
, and everything works fine.But In the webview implementation I use the url is a data url, and hydration always fails because of:
In another case, I want to parse metadata from an url using an iframe, but sveltekit apps always fail to hydrate because of a similar error:
Describe the proposed solution
Sveltekit always generates
where
new URL('.', location)
will fail whenlocation.protocol
isdata://
orabout://
Alternatives considered
No response
Importance
would make my life easier
Additional Information
No response
The text was updated successfully, but these errors were encountered: