Skip to content

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

Merged
alan-agius4 merged 2 commits into
angular:mainfrom
alan-agius4:fix-sw-modulepreload
Sep 8, 2026
Merged

fix(@angular/build): default preloadInitial to false when serviceWorker is enabled#34024
alan-agius4 merged 2 commits 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
@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
Comment thread packages/angular/build/src/builders/application/schema.json Outdated
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Sep 8, 2026
…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 merged commit d396324 into angular:main Sep 8, 2026
39 checks passed
@alan-agius4

Copy link
Copy Markdown
Collaborator Author

This PR was merged into the repository. The changes were merged into the following branches:

@alan-agius4
alan-agius4 deleted the fix-sw-modulepreload branch September 8, 2026 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/build target: minor This PR is targeted for the next minor release

Projects

None yet

2 participants