You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Defer chunks being preloaded when they should not be #30541
Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
19
Description
It seems that regular defer triggers are being prefetched despite not having prefetch on or prefetch when trigger. This was reported by one of our GDEs. This did work in past versions of Angular. So something must have changed with how these files are being bundled and inlined.
Ultimately, this would require compiler-level changes to annotate certain import calls with alternative behavior. Alternatively, we could simply avoid adding preloads for modules that aren't explicitly defined in the router configuration. However, this approach would prevent all deferred blocks from being preloaded, which may not be desirable.
As per the current documentation of the defer blocks, especially about prefetch, the alternative approach makes more sense to not preload deferred blocks until prefetch is specified. I can see how it can make it really confusing for developers to understand what @defer really does. I.e. does it download the javascript bundle on the on and when triggers? Or only render the component/load in the component tree when the triggers happen?
I think not preloading the deferred blocks makes much more sense. If someone wants to preload, they can use the prefetch keyword with their deferred blocks.
The documentation also doesn't mention that the default behavior is prefetch on idle.
Activity
alan-agius4 commentedon Jun 16, 2025
Preloading occurs when the visited route includes a lazy-loaded bundles, this feature was added in 19.1.0.
In this case, since there's a timer involved, we probably shouldn’t trigger preloading but the bundler lacks the contextual awareness. One possible solution is to enhance the Angular compiler to insert specific instructions into
importstatements: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import/with](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import/withUltimately, this would require compiler-level changes to annotate certain
importcalls with alternative behavior. Alternatively, we could simply avoid adding preloads for modules that aren't explicitly defined in the router configuration. However, this approach would prevent all deferred blocks from being preloaded, which may not be desirable.AhsanAyaz commentedon Jun 16, 2025
As per the current documentation of the defer blocks, especially about
prefetch, the alternative approach makes more sense to not preload deferred blocks untilprefetchis specified. I can see how it can make it really confusing for developers to understand what@deferreally does. I.e. does it download the javascript bundle on theonandwhentriggers? Or only render the component/load in the component tree when the triggers happen?I think not preloading the deferred blocks makes much more sense. If someone wants to preload, they can use the
prefetchkeyword with their deferred blocks.The documentation also doesn't mention that the default behavior is
prefetch on idle.fix(@angular/ssr): avoid preloading unnecessary dynamic bundles
fix(@angular/ssr): avoid preloading unnecessary dynamic bundles
fix(@angular/ssr): avoid preloading unnecessary dynamic bundles
angular-automatic-lock-bot commentedon Jul 24, 2025
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.