Skip to content

fix(@angular/build): default preloadInitial to false when serviceWorker is enabled - #34024

Open
alan-agius4 wants to merge 1 commit into
angular:mainfrom
alan-agius4:fix-sw-modulepreload
Open

fix(@angular/build): default preloadInitial to false when serviceWorker is enabled#34024
alan-agius4 wants to merge 1 commit into
angular:mainfrom
alan-agius4:fix-sw-modulepreload

Conversation

@alan-agius4

Copy link
Copy Markdown
Collaborator

When a service worker is enabled, application assets are prefetched and served from Cache Storage by the service worker. Emitting <link rel="modulepreload"> hints for initial shared chunks causes Chromium to discard them with a "cross-world service worker resource mismatch" warning on repeat visits, as well as triggering redundant network fetches.

This change sets the default of preloadInitial to false when the serviceWorker option is enabled, while still allowing developers to explicitly override it if desired.

Fixes #34022

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request changes the default behavior of preloadInitial to default to false when a service worker is enabled, and true otherwise. It also updates the JSON schema and adds tests to verify this behavior. The reviewer suggested simplifying the conditional logic for preloadInitial in options.ts using optional chaining and nullish coalescing to make it more idiomatic.

Comment thread packages/angular/build/src/builders/application/options.ts Outdated
…er is enabled

When a service worker is enabled, application assets are prefetched and served from
Cache Storage. Emitting `<link rel="modulepreload">` hints for initial shared chunks
causes Chromium to discard them with a "cross-world service worker resource mismatch"
warning on repeat visits, as well as triggering redundant network fetches.

This change sets the default of `preloadInitial` to `false` when the `serviceWorker`
option is enabled, while still allowing developers to explicitly override it if desired.

Fixes angular#34022
@alan-agius4 alan-agius4 added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release labels Sep 4, 2026
@alan-agius4
alan-agius4 requested a review from clydin September 4, 2026 07:20
@alan-agius4 alan-agius4 added target: minor This PR is targeted for the next minor release and removed target: patch This PR is targeted for the next patch release labels Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: review The PR is still awaiting reviews from at least one requested reviewer area: @angular/build target: minor This PR is targeted for the next minor release

Projects

None yet

1 participant