-
Notifications
You must be signed in to change notification settings - Fork 44
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
Support Response
in URL.createObjectURL
#97
Comments
Personally I would much rather make it possible to set the |
@wanderview that won't work for my uses which are putting the URL inside of JS which requires a string: import "blob: ..." |
After some talks with @domenic and @wanderview it seems like this might need to also have some flags setup to make 2 conditions available:
This is intended to allow garbage collecting the response body on use. Microsoft has an options bag with
I could not find any prior implementation that is doing this. I do not have a personal use for this, but the concern seems to lie in having other documents able to load URLs. Chat Log Reference: https://freenode.logbot.info/whatwg/20180212#c1432816 We could split these flags into separate PRs is my general thinking, and if that seems fine I can do so. There also seems to be a request for which environments are seeking to add this functionality. I am coming from Node so I don't know if that counts? |
I don't know if it makes sense to group this in with existing blob: URLs if the semantics are going to be so drastically different. Either way I'd really really like to avoid extending object URLs if at all possible, since for the vast majority of use cases they are a terrible hack. But okay, the three proposals mentioned here:
So since what you're describing is very different in pretty much every way from existing object URLs does it really make sense to even have this in the same API/scheme? Would it possibly make more sense to define a new scheme for this, have API on Response (or Body, but that wouldn't have access to the headers) that generates one of these new type of URLs. And for this new type of URL we could then do the: auto-revoke on first fetch (and don't resolve until they are fetched, which should be fine since we wouldn't support manual revoke), and limit scope to the realm/document that created them? That seems like it would address your usecases, without making object URLs more powerfull/complicated than they already are, and without having to support the explosion of possible configurations that introducing multiple separate flags would cause. |
Auto revocation is in the spec already and is left up to the host to define: Line 1761 in 3b94136
This doesn't seem to be a + or -?
IDK, but this seemed like the place to do it rather than try to make an entire new spec. The object URLs already have somewhat unstable lifetimes and using them after revocation can cause odd effects, this doesn't seem to add too much ontop of that in my opinion.
What is the significant difference with this and extending the existing
Wouldn't this just move the explosion to this new scheme? I'm not sure the idea of making a new scheme reduces overall complexity in any way. |
Auto revocation was in the spec, was never implemented as spec'ed, because it was never very well defined. Please refer to the latest version of the spec rather than reading old TR versions, as those are pretty much universally meaningless.
Not exactly. Specifying (and implementing) auto-revoking in a way that works with URLs that are limited to a single realm, and have different revocation logic than existing URLs is much easier than trying to somehow do the same with the existing blob URLs. So this way we don't support three different flags that could all be turned on or off, but exactly two options: Either we have the current behavior with createObjectURL, or we have this completely different behavior with a completely different API, and hot have to worry about how it interacts across realms, how it interacts with explicit revocation, how it interacts with the early resolution blob URLs need because of explicit revocation etc. So since the described behavior is different from the blob: behavior in pretty much every way, it seems to me to make a lot more sense to not try to paper over these differences and instead just keep them completely separate. That way there is no confusion as to why certain blob: URLs behave in one way why others behave completely different. |
@mkruisselbrink I have use cases that are not using some of these flags so that throws a problem up with the idea that we don't need to have flags. In particular I want to create URLs off the main thread but let the main thread load them. These are both cross realm and may not be revoked on use. |
So lets figure out what use cases there are that aren't currently supported before we jump to trying to design solutions? |
@mkruisselbrink I tried to bring this up in previous discussions in various places including a few on the previous issue and feel like I have made 0 progress in over 6 months. I would request you tell me what to do if you want me to do something in particular. |
I understand you have some use case where you for some reason need to be able to create self-referential blob URLs (or at least mutual self-referential pairs of blob URLs). I'm not sure what the motivating use case for that requirement is. And from you're earlier comments in this issue "it seems like this might need to also have some flags setup to make 2 conditions available:" it sounded like for some reason it turned out that the request in this issue required those two other options as well, so from that it seemed like it might make sense to just treat them all as one big option. But maybe I misunderstood what you were trying to say in that comment. But in either case, I don't see here or in the other issue what the use case is where you actually need these mutually recursive blob URLs. So without compelling use cases I'd be hesitant to massively complicate an already hard-to-understand part of the spec. |
@mkruisselbrink my use case is generally the creation of ESM in memory, I have mentioned that several times and even spent quite a bit of effort trying to see how to make ESM able to be instrumented in Service Workers, HTTP Servers, and seeing if I could get any hooks into the HTML specification. In general, all of this effort results in similar to the comment you had above about "what is the use case". The use cases are many but in general can be summarized as having a way to generate any non-trivial transformation of either specifier location or response body for ESM records. My annoyance is mostly coming from that not being seen as valid per your phrasing:
Which for this issue it isn't purely about mutually recursive URLs, unlike the previous one. |
Okay, so reading some of those linked issues etc, what I understand is that the use case is the desire to work around some limitations in how ES modules are resolved/loaded, and since the discussion around how to improve those limitations on the loader/html side have stalled, you came up with some way to work around the limitations on the client side, but doing that requires changes like the ones proposed in this issues? Or in other words, if the loader/html side issues get resolved somehow, would there still be a use case for this? |
@mkruisselbrink even if the loader/html hook gets added you would still need this to create a few scenarios. Namely any sort of source code transformation cannot be fully solved by the request data hook being added. So things like instrumenting code to have coverage/do local code transformations would not work unless you have a URL it can resolve to. Lets assume we have a transform of some kind that is attempting to allow import json from './foo.json'; To redirect to some newly created ESM record: // foo.json
export default JSON.parse(...) We have a few things going on here.
The problems I am currently facing are:
Only one aspect of this would be solved by that request data hook being added to the HTML spec. For more complex problems like source code transformation for JSX / Babel / code coverage / etc. doing transformations off the main UI thread is also ideal. However, doing this on the UI thread is possible. I also am coming at this from a Node.js implementer perspective and am seeking to create a parity between the two platforms while we work on our hooks for ESM. Node does not currently have a |
I'm not sure why just having a service worker wouldn't work for almost all of those cases? I understood the main issue with a service worker was the run-on-first-load case. But that shouldn't really matter for things like code coverage etc (and might be addressed by other issues anyway).
Not sure what part of the spec you think implementation aren't implementing? The spec explicitly does not allow createObjectURL in SW, since it would be both useless (the URL would expire when the SW gets killed), and not provide much benefit (you can invent your own custom URLs that you can resolve to whatever you want in your service worker). |
There is also missing data, hence why https://bmeck.github.io/node-sw-compat-loader-test/dist/test.js is changing the specifiers from simple things to extra network requests to add more data that is not available in a fetch event. Service workers also don't let you rewrite the contents imports that live in
Then lets ignore that case and just talk about code transforms and facades for now.
You can but you get into bad situations quickly, hence why https://github.com/bmeck/esm-http-server has some prefixing going on. Though that starts to leak the mutation into the client and requires the client manually do this for any entry point not coming from inside the SW (through things like people using HTML tags to load ESM). |
But that gets us back to use cases. Code transforms and facades are not use cases. They might serve to address other use cases, but without knowing those use cases it is impossible to figure out if they are the correct solution for the use case at hand. |
@mkruisselbrink what defines a use case then? You are putting basically all of transforms like JSX / transpilers / loading new content-types using facades as non-use cases. |
Not gathering what the issue is or what |
If interpret the issue and use case correctly are you trying to export and import a |
I am trying to implement code transformation for a variety of use cases in the browser. Adding
I am importing a I think there is opposition in the comments above about what a use case is and I am frustrated because there is no clear place to move forwards, so I will just have to keep opening issues in various places to see if the use case is valid given the context of where I open feature requests. |
What is "code transformation"? Have you tried using a E.g., by hand
|
What is the actual code that you are trying to implement? |
@guest271314 I am roughly trying to implement the |
Not following
nor what the actual use case is. Do you mean something like
|
Note, the above pattern was primary composed to test |
<script type="module">
import data from "data:application/javascript,export%20default%20{};";
// prints 1
setTimeout(() => console.log(data.x), 1000);
</script>
<script type="module">
import data from "data:application/javascript,export%20default%20{};";
data.x = 1;
</script> So you have to use some different scheme for generic transforms that might generate the same source text. Your code does exhibit the use case to some degree, but doesn't have the ability to intercept specifiers and referrers like https://github.com/bmeck/esm-http-server/blob/public/instrument.js is doing. Also, transformation of the |
Have not tried babel. Have minimal experience using |
What does
intend to demonstrate? Note that |
exports.js
JavaScript
provides the same results as using a |
Assigning a value to a property of a |
For Streaming/asynchronous content and for content that is intended to have specific headers that are not the defaults in a Blob based
URL.createObjectURL
workflow it would be nice to support puttingResponse
Objects as the backing resource forURL.createObjectURL
.The text was updated successfully, but these errors were encountered: