Repository navigation
module: support import()-ing blob: urls - #54647
avivkeller wants to merge 3 commits into
Conversation
|
Review requested:
|
|
The
notable-change
Please suggest a text for the release notes if you'd like to include a more detailed summary, then proceed to update the PR description with the text or a link to the notable change suggested text comment. Otherwise, the commit will be placed in the Other Notable Changes section. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #54647 +/- ##
==========================================
+ Coverage 87.34% 87.61% +0.27%
==========================================
Files 649 650 +1
Lines 182562 182847 +285
Branches 35023 35388 +365
==========================================
+ Hits 159451 160198 +747
+ Misses 16396 15926 -470
- Partials 6715 6723 +8
|
aduh95
left a comment
There was a problem hiding this comment.
Can you add a test with a loader please? We need to validate the loader thread can resolve the blob URL
There was a problem hiding this comment.
We don't need the fixtures, what I want to validate is whether it's possible to load a blob: URL generated on the main thread from the loader thread.
| `register(${JSON.stringify(fixtures.fileURL('es-module-loaders/hooks-blobify.mjs'))}, pathToFileURL("./"));`, | |
| '--import', 'data:load_blob', | |
| '--eval=""', | |
| `register("data:text/javascript,");`, | |
| '--input-type=module', | |
| '--eval', | |
| `${createURL}await import(await createURL('text/javascript', 'console.log("Loaded");'));`, |
There was a problem hiding this comment.
IIUC blobs are limited to the process that they created from, and so that won't work.
import { resolveObjectURL } from 'buffer';
import { fileURLToPath } from 'url';
import { Worker, isMainThread, parentPort, workerData } from 'worker_threads';
if (isMainThread) {
const value = await URL.createObjectURL(new Blob(['Data']));
const worker = new Worker(fileURLToPath(import.meta.url), {
workerData: { value }
});
console.log("MAIN", value, resolveObjectURL(value));
} else {
const { value } = workerData;
console.log("WORKER", value, resolveObjectURL(value));
}
I should however document that behavior.
There was a problem hiding this comment.
It has documented, but if you aren't satisfied, LMK
There was a problem hiding this comment.
That's of course very dissatisfying if blob URLs are completely broken as soon as a hook is registered, IMO we shouldn't ship something that's going to break like that.
blobs are limited to the process that they created from
To be clear, it is the same process.
There was a problem hiding this comment.
If I'm understanding how hooks work (like how I had this setup before), blob URLs will work, they just won't work from the CLI (parent->child process or parent->worker) Am I missing something in terms of how to test this?
Do you mean to call the hook with the blob URL, and load it there?
Sorry if I'm being confusing
There was a problem hiding this comment.
My suggestion is not to pass them via the CLI, just to have a test that validates blob URLs still work when there are loaders registered
There was a problem hiding this comment.
After looking into it, this is not possible, so the following note has been added to the docs: "Blob URLs are registered within the current thread. Loaders will not be able to handle resolve Blob's from the main thread."
|
CI is failing because the test isn't skipped when crypto support isn't provided. I'll fix that, along with adding the loaders test that @aduh95 suggested. |
|
Several CI failures, however (AFAICT) none of them are related, could someone re-run the failed CIs? |
aduh95
left a comment
There was a problem hiding this comment.
IMO it's not acceptable to land as stable a feature that can broken by another unflagged feature (cf #54647 (comment)). To resolve my objection, this would need to either fix the support if possible, or alternatively mark the feature as experimental, possibly behind a flag.
I'm happy to mark it experimental, as it also uses experimental APIs under the hood. IIUC the creation / resolution of blob urls is also experimental. |
|
Re-requesting review now that this is marked experimental. |
|
@mcollina are you also against this landing as experimental? |
|
I'm ok in adding as experimental if there is a path that loader hooks can be supported. It doesn't look the case atm. |
|
Until Blobs can be supported in workers, I'm afraid it seems this is a no-go. |
Fixes #47573
Notable Change
The
import()function can now receiveblob:protocol URLs as an input. These blobs must be one of the following types:text/javascriptfor ES modulesapplication/jsonfor JSONapplication/wasmfor WasmBlob URLs are registered within the current thread. Loaders will not be able to handle resolve Blob's from the main thread.