-
Notifications
You must be signed in to change notification settings - Fork 12
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
Handling of top-level await #27
Comments
As you pointed out, there are two possible alternatives:
We picked the first option because it should be possible to add top-level await to a module without it being a breaking change (modulo global side effects, that with top-level await would obviously get delayed). With the current design, using top-level await has the only effect of "disabling" part of an optimization, for a specific module. If
Unfortunately this cannot be guaranteed even ignoring top-level await. When you do For this reason, That said, now that we have import attributes I could see some platforms (or maybe the language itself one day) introducing something like import defer * as b from "./b.js" with { ifAlreadyEvaluated: "throw" } or import defer * as b from "./b.js" with { onTopLevelAwait: "throw" } |
Yeah, I see this. Of course, with the However, on reflection, I'm convinced that the
I don't consider this unexpected. I think a natural mental model for devs to bring to However, the partial immediate evaluation due to top-level Perhaps a keyword like |
@ethanresnick I'm closing this issue, but let's keep discussing the name/keyword in #6 :) |
I'm not a modules expert by any means, and I know this is a very complex space, so I'm guessing there are good reasons for the current handling of top-level await within the dependency graph of a deferred import's module.
However, as a JS user, I find the current semantics pretty unexpected and error prone, assuming I'm understanding them correctly. In particular, it seems like an import marked with
defer
can still immediately trigger side effects, via this backdoor for eagerly evaluating the async portion of the dependency graph. To me, that is deeply unintuitive because, well, I'd expect adefer
red import's evaluation to be (completely) deferred.Is there anywhere I could read about the rationale, or alternatives considered, for the current handling of top-level
await
? How does the current approach compare to, say, throwing an error upon encountering an async module within the dependency graph of a deferred import?The text was updated successfully, but these errors were encountered: