[turbopack] Discover ServiceWorkerEntryModules in next-api and compile + serve those service workers#94922
Merged
Conversation
Contributor
Stats cancelledCommit: 3fe008b |
Contributor
Tests PassedCommit: 3fe008b |
This was referenced Jun 17, 2026
bb6471e to
0f165dd
Compare
57abc66 to
a1e0472
Compare
0f165dd to
ab2d218
Compare
a1e0472 to
a12103d
Compare
ab2d218 to
964e7e5
Compare
a12103d to
a7734b1
Compare
964e7e5 to
ab06baf
Compare
a7734b1 to
6c7d8b7
Compare
bgw
approved these changes
Jun 24, 2026
Comment on lines
+72
to
+76
| bail!( | ||
| "Multiple service workers with different source files were registered for \ | ||
| scope '{scope}' ({}). Each scope serves a single service worker.", | ||
| files.join(", "), | ||
| ) |
Comment on lines
+108
to
+109
| is_production, | ||
| is_production, |
Member
There was a problem hiding this comment.
Suggested change
| is_production, | |
| is_production, | |
| /*include_traced*/ is_production, | |
| /*include_binding_usage*/ is_production, |
| let own_graph = ModuleGraph::from_graphs( | ||
| vec![SingleModuleGraph::new_with_entry( | ||
| ChunkGroupEntry::Entry(vec![module]), | ||
| is_production, |
Member
There was a problem hiding this comment.
Should use Project::should_write_nft_manifests?
| is_production, | ||
| is_production, | ||
| )], | ||
| None, |
Member
There was a problem hiding this comment.
Suggested change
| None, | |
| /*binding_usage*/ None, |
Comment on lines
+120
to
+121
| OutputAssets::empty(), | ||
| OutputAssets::empty(), |
Member
There was a problem hiding this comment.
Suggested change
| OutputAssets::empty(), | |
| OutputAssets::empty(), | |
| /*extra_chunks*/ OutputAssets::empty(), | |
| /*extra_referenced_chunks*/ OutputAssets::empty(), |
ab06baf to
d040635
Compare
d040635 to
412d654
Compare
6c7d8b7 to
adf44b5
Compare
…mpile + serve those service workers
adf44b5 to
3fe008b
Compare
38f75c7
into
sp/turbopack/single-entry-chunks
137 of 139 checks passed
sampoder
added a commit
that referenced
this pull request
Jun 29, 2026
This PR is the PR that "turns on" the service worker feature, this is
because in the analyzer we are now looking for code like:
```
await navigator.serviceWorker.register(new URL('../lib/service-workers/1.js', import.meta.url), ...)
```
And transforms it into registering the URL that Next.js will now serve
based on scope.
URL scheme is:
```
scope: "/" -> `sw.js`
scope: "/offline/mode" -> `sw-offline-mode.js`
```
etc.
It also inserts the `ServiceWorkerEntryModule`s so they can be
discovered by `next-api` (see
#94922).
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.
This is the big change in the
next-part of the repo to support this. The code goes through the module graph to find any service workers that need compiling and then compiles them. It also has the code changes topackages/next/src/server/lib/router-utils/filesystem.tsthat serve these files on their respective routes.