PWA not working with vite-based dev server
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 35/100
- Type d'issue
- Bug
- Clarté
- Plutôt claire
- Activité
- À l'abandon
- Stack technique
- angular, typescript, vite
- Domaine
- build-system, cli, web-dev
Piste de recherche
Reproduisez le problème du dépôt pwa-repro lié avec les commits de Vite et webpack, en utilisant npm install et ng serve. Inspectez ngsw.json, ngsw-worker.js et la sortie de /ngsw/state, puis comparez les fichiers générés et les hashes entre les deux serveurs. C'est terminé lorsque le serveur de développement Vite ne provoque plus de différence de hash du service worker.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Command
serve
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
Angular 16
Description
Serving a PWA with the default dev server is now broken.
Specifically, the vite dev server apparently mangles the files emitted by the previous build steps, but does not recompute the hashes stored in ngsw.json.
This results in the service worker being installed, but not really serving any file.
It is still possible to use the "old" (webpack-based) dev server that is apparently not affected by this.
Minimal Reproduction
Basically the steps are:
- create a new app
ng new - make it a PWA
ng add @angular/pwa - configure it to start the service worker in dev
- start it
ng serve - open it in the browser http://localhost:4200/ and wait a few seconds (so that the service worker can initialize)
- check the sw state at http://localhost:4200/ngsw/state
A full repo reproducing the issue is https://github.com/ranma42/pwa-repro
From this repo, the needed steps are:
- choose the commit to start from (https://github.com/ranma42/pwa-repro/commit/a524b1a36049d77690ac6f37c14a56d1d501a042 to check the issue with vite, https://github.com/ranma42/pwa-repro/commit/6207a68be012eb680e000ff02f82b65c1d6b4b8d to compare with webpack)
- install the dependencies
npm install - start the server
ng serve - open the app in the browser http://localhost:4200/ and wait a few seconds (so that the service worker can initialize)
- check the sw state at http://localhost:4200/ngsw/state
Note that the repo contains both a revision that reproduces the issue and one that configures the build to use webpack for comparison, to show that in that case the dev server works as intended.
Also note that to properly check what is going on, you might want to clear the browser state by opening the inspector and (in Chrome-based browsers) going to Application -> Storage -> Clear site data
With the webpack dev server, http://localhost:4200/ngsw/state reports
NGSW Debug Info:
Driver version: 18.2.0
Driver state: NORMAL ((nominal))
Latest manifest hash: a9c562165e1a3b3bf67ea36a6e0537b1075767a8
Last update check: 38s35u
=== Version a9c562165e1a3b3bf67ea36a6e0537b1075767a8 ===
Clients: 946e5332-b1f0-466c-94fe-fac62101a798, 01aa5e79-986a-4910-bf75-eebbd80ad320
=== Idle Task Queue ===
Last update tick: 196u
Last update run: 27s738u
Task queue:
Debug log:
Exception or Error
For the vite devserver http://localhost:4200/ngsw/state reports
NGSW Debug Info:
Driver version: 18.2.0
Driver state: EXISTING_CLIENTS_ONLY (Degraded due to: Hash mismatch (cacheBustedFetchFromNetwork): http://localhost:4200/index.html: expected dcc35fd9e7cb2cbc5727f7dc941ab15beb5c8e94, got c628b20918af9ae65adf19ae7ef74c3c9d168ca7 (after cache busting)
Error: Hash mismatch (cacheBustedFetchFromNetwork): http://localhost:4200/index.html: expected dcc35fd9e7cb2cbc5727f7dc941ab15beb5c8e94, got c628b20918af9ae65adf19ae7ef74c3c9d168ca7 (after cache busting)
at PrefetchAssetGroup.cacheBustedFetchFromNetwork (http://localhost:4200/ngsw-worker.js:476:21)
at async PrefetchAssetGroup.fetchFromNetwork (http://localhost:4200/ngsw-worker.js:451:19)
at async PrefetchAssetGroup.fetchAndCacheOnce (http://localhost:4200/ngsw-worker.js:430:21)
at async http://localhost:4200/ngsw-worker.js:535:9
at async http://localhost:4200/ngsw-worker.js:521:9
at async http://localhost:4200/ngsw-worker.js:521:9
at async http://localhost:4200/ngsw-worker.js:521:9
at async http://localhost:4200/ngsw-worker.js:521:9
at async PrefetchAssetGroup.initializeFully (http://localhost:4200/ngsw-worker.js:520:7)
at async http://localhost:4200/ngsw-worker.js:924:11)
Latest manifest hash: 92656589d404e75dc7df6ccfe2840f76f7867faa
Last update check: 6s797u
=== Version 92656589d404e75dc7df6ccfe2840f76f7867faa ===
Clients:
=== Idle Task Queue ===
Last update tick: 4s224u
Last update run: never
Task queue:
* activate: cleanup-old-sw-caches
* init post-load (cleanup)
Debug log:
[6s755u] Error(Hash mismatch (cacheBustedFetchFromNetwork): http://localhost:4200/index.html: expected dcc35fd9e7cb2cbc5727f7dc941ab15beb5c8e94, got c628b20918af9ae65adf19ae7ef74c3c9d168ca7 (after cache busting), Error: Hash mismatch (cacheBustedFetchFromNetwork): http://localhost:4200/index.html: expected dcc35fd9e7cb2cbc5727f7dc941ab15beb5c8e94, got c628b20918af9ae65adf19ae7ef74c3c9d168ca7 (after cache busting)
at PrefetchAssetGroup.cacheBustedFetchFromNetwork (http://localhost:4200/ngsw-worker.js:476:21)
at async PrefetchAssetGroup.fetchFromNetwork (http://localhost:4200/ngsw-worker.js:451:19)
at async PrefetchAssetGroup.fetchAndCacheOnce (http://localhost:4200/ngsw-worker.js:430:21)
at async http://localhost:4200/ngsw-worker.js:535:9
at async http://localhost:4200/ngsw-worker.js:521:9
at async http://localhost:4200/ngsw-worker.js:521:9
at async http://localhost:4200/ngsw-worker.js:521:9
at async http://localhost:4200/ngsw-worker.js:521:9
at async PrefetchAssetGroup.initializeFully (http://localhost:4200/ngsw-worker.js:520:7)
at async http://localhost:4200/ngsw-worker.js:924:11) initializeFully for 92656589d404e75dc7df6ccfe2840f76f7867faa
Your Environment
$ ng version
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 18.2.0
Node: 20.13.0
Package Manager: npm 10.5.2
OS: linux x64
Angular: 18.2.0
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
... service-worker
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1802.0
@angular-devkit/build-angular 18.2.0
@angular-devkit/core 18.2.0
@angular-devkit/schematics 18.2.0
@schematics/angular 18.2.0
rxjs 7.8.1
typescript 5.5.4
zone.js 0.14.10
Anything else relevant?
No response
- Langage dominant
- TypeScript
- Étoiles
- 27k
- Forks
- 11.8k
- Merge moyen
- 16 h 35 min
- PR mergées (30 j)
- 176
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de angular/angular-cli
-
Can't use an array of hostnames in --allowedHosts cli parameter in @angular/build:dev-server Ouvertearea: @angular/build gemini-triaged
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
angular/angular-cli#33955 ·
-
area: @angular/cli gemini-triaged
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
angular/angular-cli#33055 · 1 commentaire · 3 réactions ·
-
unit-test: with --coverage, a setup file's hooks reach only the first spec file of each worker Ouvertearea: @angular/build gemini-triaged
Difficulté 4/5 3-5 jours Accessibilité débutants 72/100
angular/angular-cli#34137 ·
-
angular/build:library area: @angular/build gemini-triaged
angular/angular-cli#34131 · 1 personne assignée ·
-
angular/build:library area: @angular/build gemini-triaged
angular/angular-cli#34130 · 1 personne assignée ·
Toutes les issues de angular/angular-cli
Issues similaires
-
S: triage
Difficulté 1/5 Moins d'une heure Accessibilité débutants 85/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
-
fix(errors): EHOSTUNREACH from a happy-eyeballs connect is reported as a resolver error (STAMP-80) Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 90/100
snapshot-labs/stamp#666 ·
-
fix(api): prevent leaderboard SSE heartbeat from starting after disconnect during initial load Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
GauravKarakoti/SecureFlow#1070 · 1 commentaire ·
-
feature:Languages/Translations good first issue ready Web
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
digitalfabrik/integreat-app#4394 ·