-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
discussion: --location=<URL> option #4981
Comments
I hadn't paid attention to this. I think it is an inevitability to be able to provide full API capabilities for the web. I know we had debates before around this for |
The reason for #3520 was that we were squatting a web API for something that has no isomorphic usage just because we could. However, at the time we were talking about "using Nevertheless, it's scary and opinionated to assign our own default to a web API and I seriously question that we need one. When we unsupported this for Workers, people seeking help with the breakage didn't really know what their relative paths were being based onto in the first place. The default resolution aligned with their unmindful expectation, so they wrote code that was dependent on an environmental factor without realising. We should reduce these. By now it's been proven that this "convenience" isn't needed in favour of what people do now: Let's instead invite people to use
|
That is logical. I agree people mis-understanding what they thought they needed when using a web API, and I can see the logic that there is no good universal rule of what it should be, or what someone needs it to be, and actually a location that is a reference to a local file would be unusable for most folks and not really help portability of code. So a default being "wrong" most of the time doesn't make for a good default. I think we would want some good rules about behaviour with it missing though, and would be especially useful if a hint was given "why don't you try that again with @nayeemrmn can you think of any risks with allowing this to be set from within the sandbox? Like allowing |
I landed on this, for maximum forward-compatibility: Object.defineProperty(globalThis, "location", {
get() {
if (locationFromOpStart == null) {
throw new ReferenceError(
`Access to "globalThis.location", run again with --location=<href>.`,
);
}
return locationFromOpStart;
},
// A similar setter would be applied to fields of `locationFromOpStart`.
set() {
throw new TypeError(`Cannot set "globalThis.location".`);
},
}); This would make scripts that feature-test for When setting, I was going to say that there's an expectation of navigation so we should throw rather than silently doing nothing. But I guess there are ways of setting it without unloading (e.g. |
Here are some use-cases which I have that would be directly solved by this issue: Isomorphic Server Side RenderingDeno is already a great choice for isomorphic server side rendering because it implements many web APIs like // server side generation bootstrap script
window.location = new URL("https://myfakepage.com/foo/bar");
// actual server side component
const res = await fetch(new URL("/api/me", window.location)); With |
Reading material: whatwg/html#1888 |
In #1657 (comment) an
--origin=https://example.com
option is proposed to select whichlocalStorage
isolate is used by the process. This could also be used for lots of other purposes.For a consistent analogy we should extend this to a
--location=https://example.com/<path>
which selects the location for all web API purposes, including but not limited to:window.location
.fetch()
relative resolution root.Worker
module relative resolution root.localStorage
origin.Origin
header for any built-in HTTP requests.Without an explicit
--location
,globalThis.location
should throw,localStorage
should be non-persistent and document-relative URLs for the other purposes should fail. This makes--location
act as the gate requested for persistent storage: #1657 (comment).Not having a default might be controversial, but this lets us abstain from any opinionated design decisions for the first version.
JS API:
The text was updated successfully, but these errors were encountered: