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
Feature: Workerized JS Module Script Loading #13
Comments
This might also be beneficial to syncify some loader hooks. For example it is seeming more and more likely Chromium wants to ship a synchronous |
Synchronous |
Thinking out loud about all the potential use-cases for loaders being discussed: Do any of the http loader use-cases currently assume the ability to make http requests within It's no problem for |
None of the examples in https://github.com/nodejs/loaders/blob/main/doc/design/proposal-chaining-recursive.md currently do, but I think it’s easily conceivable that a loader might want an async |
Oh right, something like the unpkg example is what I keep mentally returning to: a loader with resolution logic that requires looking up files / directories / URLs first, such as consulting a If the resolved URL is dependent on async logic, then I don't think it can be moved into Is the goal to implement synchronous |
So, all I have for Web stuff is: https://github.com/DerekNonGeneric/web-context-js The "specifier" part is "opaque" (defined by "host"), until "import maps" finally ships (did it?), that would be a no. We cannot use "http" at all currently, (nor do we to my knowledge, that is a Deno-only thing currently). |
@DerekNonGeneric looks like no, import maps have not yet landed 😢 nodejs/node#49443 For remote resolution (which would suggest needing to check outside knowledge), I would expect a prefix like what @bmeck does in his module mock PR. An import map could suffice, but puts a wee bit more onus on the user who then needs to be aware of Continuing with unpkg, This (as well as import-map) also works in scenarios where packages/modules are created during the app's lifetime (such as what Framer.com do constantly): resolve doesn't need to be aware of the new package/module, only how to find it. If the other side of the URL has a If I understand it correctly, If it's possible to keep |
@guybedford what would be the reason browsers want a sync |
@giltayar with import maps, the initial URL in a browser is synchronously available. The final URL, of course, would be both variable and also async, but I can certainly see the need for a sync API to determine the first network request URL that will be contacted. (no idea if browsers actually want this or not, ofc) |
@ljharb I can see that initially they don't really need an async api, but they would be closing the door on a browser loader api that should be (IMO) async. |
Right, I was always personally hopeful for an async resolve hook because of the possibility of dynamic resolution, which could seem important not to rule out. It's at a little bit of an impasse between Node.js and the browser right now (and there is an HTML PR up for a sync import.meta.resolve). Hopefully putting thought to dynamic import maps will shed some light on this question up again for browsers, ideally when firefox implement import maps. |
Node and browsers are different; there's really nothing wrong with making a different name - if browsers make a sync resolve, node could provide an async one named something else, and folks who want to write code universally can feature-detect. |
@ljharb having two resolves (a sync and an async one) doesn't solve the problem. Because once there is a sync resolve, then the "resolve" loader hook MUST be sync, which will preclude async resolutions (e.g. HTTP). (and, yes, I know we can now do sync HTTP using workers and atomics, but that means that the loader needs to create a worker for this, which isn't a lightweight option.) Just putting it here. It's not like there's something that can be done in this context. 😊 |
I apologize for allowing this issue to get completely derailed from the original goal. We seem to have one global object missing needed to support some sort of “Workerized JS Module Script Loading” according to an unofficial draft specification in the WICG. I have linked to the issue below — it looks interesting… This is somewhat relevant and necessary for interop (with who is not the important part, but perhaps to achieve the goal of having “Worklet Infrastructure” outlined in that specification being the important part). |
There seems to be a good amount of momentum behind This API may still not be up to snuff for us as it's currently specced as mentioned in the original issue (need more info). I guess I wouldn't get my hopes up too soon — it looks like something we should keep our eyes on (maybe even potentially review their spec and participate if we know of any ways to optimize to make it more usable on the backend). Seeing as how non-browser environments would sometimes have a filesystem path rather than an actual URL (as in the case of CommonJS specifiers), I wonder how optimal this may be for us? I almost wish it could handle filesystem paths, too; otherwise, we'd have to normalize some specifiers using
I still haven't heard too much interest from the loaders team about this yet… |
@DerekNonGeneric I at least in the Loaders side of things don't see the need for URLPattern or even the advantage to using it. For example, if we scope things using URLPattern that means a cost prior to doing any operation. Additionally it uses string based semantics and really is best suited for HTTP/HTTPS and not mixing with other URL schemes. Im especially confused on how this relates to putting stuff in workers. |
The future (and hopefully very near future) way to achieve performative module script loading will likely come in the form of implementing “worklet infrastructure” in core since it does not seem like a userland solution should be reasonably expected.
This issue should help us track progress in this area, which I find to be of great interest.
The text was updated successfully, but these errors were encountered: