feat(core): Adds @defer retry for failed dependency loads#68738
Open
SkyZeroZx wants to merge 1 commit into
Open
feat(core): Adds @defer retry for failed dependency loads#68738SkyZeroZx wants to merge 1 commit into
@defer retry for failed dependency loads#68738SkyZeroZx wants to merge 1 commit into
Conversation
Introduces support for retrying failed `@defer` block dependency loads via a new `@error` (retry N) parameter. This feature allows applications to automatically recover from transient network failures or intermittent issues by re-attempting the chunk download up to N times. Each retry attempt automatically applies cache-busting to bypass browser caching of failed dynamic imports. A new `provideDeferBlockRetryHandler` public API enables customization of the retry mechanism. This hook empowers advanced use cases such as exponential backoff. Compiler changes wrap dynamic imports in "thunks," allowing the `DeferBlockRetryHandler` to access the original import function for re-invocation and URL inspection. Closes angular#52800
SkyZeroZx
commented
May 14, 2026
| // | ||
| // `@vite-ignore` must stay as its own exact comment so Vite suppresses the | ||
| // "dynamic import cannot be analyzed" warning. | ||
| return import(/* @vite-ignore */ retryUrl).then((mod) => { |
Contributor
Author
There was a problem hiding this comment.
An additional point is that this will only work with EsBuild/Vite; in the case of webpack, since it uses a global variable, it's a bit more complex (and considering it's been deprecated, I don't think it's worth adding support for it).
And a patch will probably be needed to keep the vite-ignore comment, otherwise we'll get a warning on the dev server.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduces support for retrying failed
@deferblock dependency loads via a new@error(retry N) parameter. This feature allows applications to automatically recover from transient network failures or intermittent issues by re-attempting the chunk download up to N times. Each retry attempt automatically applies cache-busting to bypass browser caching of failed dynamic imports.A new
provideDeferBlockRetryHandlerpublic API enables customization of the retry mechanism. This hook empowers advanced use cases such as exponential backoff.Compiler changes wrap dynamic imports in "thunks," allowing the
DeferBlockRetryHandlerto access the original import function for re-invocation and URL inspection.Closes #52800
Other information
The proposed syntax
@defer (on idle) { <app-large-flaky /> } @loading (minimum 200ms) { <p>Loading… </p> } @error (retry 3) { <p>All retries exhausted </p> }Another alternative could be
@defer (on idle) { <app-large-flaky /> } @loading (minimum 200ms) { <p>Loading… </p> } @error ({retry:3 , otherParamsHere... }) { <p>All retries exhausted </p> }However, considering we can customize with a provider, it might not be worthwhile atm.
Customizing retry behavior
I was also inspired by Vue, which has a similar API,
defineAsyncComponent.Repository as a Proof of Concept : https://github.com/SkyZeroZx/defer-retry-poc
retry.demo.mp4