Replies: 1 comment
-
I think going through the discussions in this issue could be helpful: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Vite adds a hash to each js chunk, asset, and as well as to the main.js file. It does this in order to let the client know that the file has been changed and it needs to download the new one. I have a handler in my Vue app router that in case of an error loading dynamic module will refresh the page and thus find out the new hashes & new files. The problem is if a hash of the main.js file is being changed the website doesn't get to load the Vue router and doesn't pass through this error handler. It gets stuck in a blank index.html document until a manual refresh of a website. Did anyone consider adding an error handler to the
<script type="module" src="/src/main.hash1.js"></script>
in the HTML file? My idea is:
<script type="module" src="/src/main.hash1.js" onerror="onMainScriptLoadingError"></script>
and inside of
onMainScriptLoadingError
putting awindow.location.reload();
depending on some value stored in localStorage. On one hand to reload the page and download the new index.html with new main.hash2.js to be able to load the new assets. On the other hand to avoid the infinite refresh loop (variable in localStorage with the date of the last forced refresh or something similar).The only 'solution' I found is leaving the old main.hash1.js historic files but I don't want to end up with 1000 main.js files on the server. I don't want either to relate the CI/CD build to the previous build. Want to keep it separated & independent.
Any ideas? Does it all make sense? Why isn't it proposed as a solution during instalation? Are there other ways to handle it?
EDIT: to clarify the case. The client has a Chrome tab opened with a Vue app loaded and changes to another tab. In the meantime we deploy a new version, the hash of main.js file gets changed (to main.hash2.js) but the client still has the old version of index.html pointing to the old main.hash1.js file. It does not encounter the file on the server and leaves the page blank as no main.js script is loaded from the index.html. Log error assets/main.9152584e.js:1 Failed to load resource: the server responded with a status of 404 (). I'm investigating now if it is related to memory saving in Chrome >110. It might release the memory for js files but not for html index and that could cause this problem.
Beta Was this translation helpful? Give feedback.
All reactions