SAP / spartacus

Spartacus is a lean, Angular-based JavaScript storefront for SAP Commerce Cloud that communicates exclusively through the Commerce REST API.
Apache License 2.0
744 stars 389 forks source link

index.html hash mismatch in CCV2 Cloud when using pwa #18092

Open janwidmer opened 1 year ago

janwidmer commented 1 year ago

Describe the bug When using the PWA feature of spartacus, a Service Worker is being installed in the user's client. Part of the Service Worker is the ngsw config, where we can define asset and data groups.

Part of the ngsw config in the dist folder is the hash table for all application dist files containing a hash based on the file content. This hash table is used by the service worker to distinguish, if there is an update or not.

This works for all assets except for the index.html file. The problem with the index html file is, that the file get's edited during the server startup in the CCV2 Cloud by the build script to inject the OCC Base url.

After that editing, the hash in the ngsw config does not match with the hash of the file anymore, since it's file content has changed.

This leads to a hash mismatch error in the service worker and the service worker / pwa does not work correctly anymore. image

Tell us the version of Spartacus

To Reproduce Steps to reproduce the behavior:

  1. Create a fresh spartacus project
  2. Enable pwa
  3. Deploy it to the CCV2 Cloud
  4. Do a second deployment
  5. Check the page /ngsw/state
  6. Notice the hash mismatch error

Expected behavior After the CCV2 Build changed the index.html file content, the ngsw hash table is regenerated. Use a tool like https://github.com/dev-jan/ngsw-rehash to regenerate it

Desktop (please complete the following information): all devices

Smartphone (please complete the following information): all devices

Additional context This is an issue of the CCV2 Cloud.

wangzixi-diablo commented 10 months ago

CXSPA-5788 created for it.