-
Notifications
You must be signed in to change notification settings - Fork 47
Retry failed dynamic import #80
Comments
I've added an item to the upcoming TC39 agenda to discuss loosening this restriction. In particular I think it should match the requirements of HostResolveImportedModule so that failures are not required to be cached. If we get TC39 signoff for allowing hosts (like web browsers) to not cache the results, the bulk of the work here would be done in the HTML Standard repository, which specifies exactly how URLs are fetched and the results are cached. @hiroshige-g and I are exploring this space a bit. Tentatively we have the following thoughts:
|
Thanks for your answer and I like your idea.
|
Personally I think it would be better to only allow retry of modules that failed due to errors during the link stage (but not parsing errors). This would cover cases where if a module failed to fetch but wouldn't allow retry-ing a module that simply throws an error during evaluation (e.g. wrong environment). |
@Jamesernator I am confused by your statement. Evaluation errors are not parsing errors. |
From the diagram it seems to imply that given this: // file1.js
console.log("Hello!");
throw new Error("Failed!"); // file2.js
import("./file1.js")
.catch(err => import("./file2.js")); Would print |
Even though I didn't mean to have this as a possibility during the creation of the graph, I see some usecases where it would be good to retry any failed module which didn't yet resolve successfully. On the other hand the sideeffects would be really unexpected as a developer and I always see cases where a module might break in weired ways because of a retry after execution start. Overall I agree that your example should indeed only log |
|
…ynamically This better matches HostResolveImportedModule, which only requires idempotency when it completes normally (which is analogous to the success case here). Closes tc39/proposal-dynamic-import#80, at least on the ECMAScript side.
This allows failures to become successes on later calls. This better matches HostResolveImportedModule, which only requires idempotency when it completes normally (which is analogous to the success case here). Closes tc39/proposal-dynamic-import#80, at least on the ECMAScript side.
) This allows failures to become successes on later calls. This better matches HostResolveImportedModule, which only requires idempotency when it completes normally (which is analogous to the success case here). Closes tc39/proposal-dynamic-import#80, at least on the ECMAScript side.
Closing this since Domenic's issue was closed and this is no a duplicate. Might be interesting to force the retry on failed by the spec, but in the means of this issue the current solution is fine. |
Sorry to add to a close issue... Just double checking. Am I right in saying that this behaviour has now been rectified, and that future browsers will indeed re-attempt loading failed imports? And, do you guys know which version of Chrome/Safari is taking on the correct behaviour? Is there a ticket anywhere? I am trying to decide if I should scrap dynamic imports altogether for my SPA, since this limitation basically renders my code useless -- and dynamic imports for SPAs kind of unworkable... |
TLDR: Retrying a once failed dynamic import is not possible without hacking around the browser and spec and this leads once failed imports to get blocked for the whole session.
In the current version of the proposal it's declared, that a once failed import should always fail in the future (1.1.2 - 3).
In my understanding this came from the fact, that a once resolved import should always return the same module instance so two calls to the same import don't retrigger the module setup.
To this point I'm completely in favour of the proposal since it matches as closely as possible the static import.
But if we now change from successful imports to a failed import I can't see the need to not retry an earlier failed import. A typical usecase would be to have a single page app which loads custom elements as modules as they are needed. If a user now has a short network outage he will never during his session be able to reimport that module (a hacky workaround is to add a nonce to the url, but that also breaks the "each module is only instantiated once" rule since now one module becomes two).
In my opinion a call to import should work the following way:
That way it's possible to retry a failed import and you don't need to hack around the browser and specification like described above. This would not touch static import in any way and there's already the misconception out there that dynamic import is retryable.
If there is any reason except for ease of implementation for the browsers to keep the current behavior for dynamic import, please let me know.
The text was updated successfully, but these errors were encountered: