Openbravo Issue Tracking System - POS2
View Issue Details
0050846POS2Corepublic2022-11-10 13:212022-11-14 16:51
cberner 
cberner 
normalmajorhave not tried
closedfixed 
5
 
22Q4.122Q4.1 
No
0050846: On occasions service worker doesn't properly use the updated files
It seems on occasions, there is a reload of the application when a new version of the builds is present and the files being used after the refresh are the same as the old version, another refresh is required for this to be fixed afterwards.

The main problem seems to be that the reload of the application could generate a race condition with the activation of the new service worker, we should refresh only afterwards.
1. Apply this diff serviceWorker.diff attached, it adds a setTimeout on the processing of the skipWaiting message of the service worker
2. Run ant build in core2
3. Start Tomcat server, and use the production build: localhost:8080/openbravo/web/pos
4. Modify the service-worker.js file in WebContent/web/pos/static to generate a new update, you can modify one of the .chunk.js files to see which one is the web page currently using

After modification, refresh the webpage, check that we're still using the older version, instead of the new one. You can check this by looking in dev-tools at the Sources tab, check the files that you modified and updated the version.
Refresh the application on service worker activation, after the messages has been properly created.
No tags attached.
blocks defect 0050836 closed cberner On occasions service worker doesn't properly use the updated files 
Issue History
2022-11-10 16:45guilleaerTypedefect => backport
2022-11-10 16:45guilleaerTarget Version => 22Q4.1
2022-11-14 16:03hgbotNote Added: 0143581
2022-11-14 16:51hgbotResolutionopen => fixed
2022-11-14 16:51hgbotStatusscheduled => closed
2022-11-14 16:51hgbotFixed in Version => 22Q4.1
2022-11-14 16:51hgbotNote Added: 0143585
2022-11-14 16:51hgbotNote Added: 0143588

Notes
(0143581)
hgbot   
2022-11-14 16:03   
Merge Request created: https://gitlab.com/openbravo/product/pmods/org.openbravo.core2/-/merge_requests/914 [^]
(0143585)
hgbot   
2022-11-14 16:51   
Directly closing issue as related merge request is already approved.

Repository: https://gitlab.com/openbravo/product/pmods/org.openbravo.core2 [^]
Changeset: aa28c314febdabc03b312484b0994b71332e9de8
Author: Cristian Berner <cristian.berner@openbravo.com>
Date: 14-11-2022 16:03:03
URL: https://gitlab.com/openbravo/product/pmods/org.openbravo.core2/-/commit/aa28c314febdabc03b312484b0994b71332e9de8 [^]

Fixes ISSUE-50846: On occasions service worker doesn't properly use the updated files

There is a race-condition when changes are detected in the service
worker, and a reload is required. The reload was happening just after
sending a Skip Waiting message to the service-worker thread, which
sometimes does not allow the service worker to finish its process of
fetching + activation, as such it will keep old version .js files until
another refresh happens.

To avoid this, we refresh the application after we sent the message, but
once the service worker is not waiting anymore, and is in an "activated"
state.

---
M web-jspack/org.openbravo.core2/src/registerServiceWorker.js
---
(0143588)
hgbot   
2022-11-14 16:51   
Merge request merged: https://gitlab.com/openbravo/product/pmods/org.openbravo.core2/-/merge_requests/914 [^]