Conversation
web-mapviewer
|
||||||||||||||||||||||||||||
| Project |
web-mapviewer
|
| Branch Review |
feat-pb-1878-version-service-worker
|
| Run status |
|
| Run duration | 07m 14s |
| Commit |
|
| Committer | Felix Sommer |
| View all properties for this run ↗︎ | |
| Test results | |
|---|---|
|
|
0
|
|
|
0
|
|
|
20
|
|
|
0
|
|
|
261
|
| View all changes introduced in this branch ↗︎ | |
6ff5242 to
f017012
Compare
77eec5e to
89d3caa
Compare
There was a problem hiding this comment.
Pull request overview
This PR implements service worker versioning by moving the generated service worker file into a versioned directory structure. The implementation adds two new Vite plugins to handle the versioning process and updates the application to validate the service worker configuration at runtime.
Changes:
- Added two new Vite plugins: one to validate service worker registration patterns and emit a validation file, another to move the service worker to a versioned directory with a bootstrap loader
- Updated build info generation to include service worker path information based on build mode
- Enhanced offline readiness status component to validate SW configuration, handle insecure contexts, and display appropriate error states
- Refactored service worker to use
import.meta.env.MODEinstead ofIS_TESTING_WITH_CYPRESSand conditionally register navigation routes only in non-dev builds
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/mapviewer/vite.config.mts | Added imports and configuration for new SW versioning plugins, passed mode parameter to build info plugin, added console logging for build mode |
| packages/mapviewer/vite-plugins/vite-plugin-version-sw-path.js | New plugin that validates SW registration patterns in build output and emits a validation JSON file |
| packages/mapviewer/vite-plugins/vite-plugin-move-sw.js | New plugin that moves the generated SW file to a versioned directory and creates a bootstrap loader at the root |
| packages/mapviewer/vite-plugins/vite-plugin-generate-build-info.js | Updated to accept mode parameter and include SW path information in build info output |
| packages/mapviewer/src/utils/offline/OfflineReadinessStatus.vue | Added SW validation checking, insecure context detection, error state management, and updated UI to display various SW states |
| packages/mapviewer/src/service-workers.ts | Replaced IS_TESTING_WITH_CYPRESS with import.meta.env.MODE check, added log statements, and made navigation route registration conditional on non-dev mode |
| packages/mapviewer/tests/cypress/tests-e2e/featureSelection.cy.js | Removed unnecessary blank line |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/mapviewer/src/utils/offline/OfflineReadinessStatus.vue
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
e315d5a to
a7dd498
Compare
pakb
left a comment
There was a problem hiding this comment.
looking good so far, I have one general question about the second plugin
I think we should translate all the text you've added to the Vue component too (but I'm guessing you were waiting for a technical review first)
| /** | ||
| * Vite plugin that validates the service worker registration path and emits a build validation file. | ||
| * | ||
| * This plugin: | ||
| * 1. Finds chunks containing service worker registration code from the virtual:pwa-register module | ||
| * 2. Validates that the registration path remains "./service-workers.js" (root scope-safe path) | ||
| * 3. Emits a validation file (sw-ready.json) to indicate successful configuration | ||
| * 4. Warns if no SW registration pattern is found (validation failure) | ||
| */ |
There was a problem hiding this comment.
What is exactly the problem that this plugin is trying to detect?
A failed build?
There was a problem hiding this comment.
The plugin moves the service-worker.js file to ${appVersion}/service-workers.js if this was not successful, it logs the warning but it will not make the build fail
There was a problem hiding this comment.
So in case this sw-ready.json isn't created, the build doesn't fail and continue its course. Then the app loads that and does not activate SW at all because of the missing file? So it kind of revert back to simple load of the page?
I'm not 100% sure how this will behave whilst having already cached/loaded SW environment in the browser though
I'm a bit afraid the browser will stick to its latest valid version it has in the cache
There was a problem hiding this comment.
The sw-ready.json file does not have any functionality regarding the service worker itself, it is only there for the OfflineReadinessStatus.vue to show an error if the service worker validation failed, but the service worker is working independently from it.
The browser uses normal SW lifecycle: install -> waiting/active -> claim/update.
If the new /service-workers.js is reachable and changed, it can update to the new service worker.
If the update path is broken, browser keeps last valid active SW
btw i noticed when i tested on the phone, that the offline readiness status is not visible on mobile, where it is mostly used, so we might want to add that on the mobile view
9fd379a to
9770a0a
Compare
9770a0a to
8ea660e
Compare
8ea660e to
14225c9
Compare
pakb
left a comment
There was a problem hiding this comment.
LGTM so far, what I propose we do, if you think this could be ready to be tested "live" is that we could ship this change as a single version (no other changes).
This way we can quickly rollback if we see it's not behaving as planned
Service Worker Files and Workflow (Build + Runtime)
Files involved
packages/mapviewer/src/service-workers.tsdist/service-workers.js(root)./service-workers.js).dist/<appVersion>/service-workers.jsdist/<appVersion>/sw-ready.jsonvite-plugin-version-sw-path).Build-time workflow
VitePWA builds the SW
service-workers.tsintodist/service-workers.js(and optional map).vite-plugin-move-swrunsdist/service-workers.js→dist/<appVersion>/service-workers.js.dist/service-workers.jsas bootstrap:importScripts('./<appVersion>/service-workers.js')vite-plugin-version-sw-pathruns"./service-workers.js").dist/<appVersion>/sw-ready.jsonwith validation metadata.What each file does
Root
service-workers.jsVersioned
/<appVersion>/service-workers.jssw-ready.jsonswVersioned,version,timestamp, etc.).Runtime workflow (when user opens app)
./service-workers.js.importScripts.self.__WB_MANIFEST)skipWaiting()+clientsClaim()for fast takeoverNetworkFirstin your code).Why versioning matters
Test link