fix(chunk-loading): handle stale chunk loading errors - #4100
Conversation
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## main #4100 +/- ##
==========================================
- Coverage 98.77% 98.74% -0.04%
==========================================
Files 823 823
Lines 15147 15162 +15
Branches 4387 4389 +2
==========================================
+ Hits 14961 14971 +10
- Misses 179 183 +4
- Partials 7 8 +1
Continue to review full report in Codecov by Sentry.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4100 +/- ##
==========================================
- Coverage 98.77% 98.74% -0.04%
==========================================
Files 823 823
Lines 15147 15162 +15
Branches 4387 4381 -6
==========================================
+ Hits 14961 14971 +10
- Misses 179 183 +4
- Partials 7 8 +1
Continue to review full report in Codecov by Harness.
|
Codecov ReportAttention: Patch coverage is
✅ All tests successful. No failed tests found.
@@ Coverage Diff @@
## main #4100 +/- ##
==========================================
- Coverage 98.77% 98.74% -0.04%
==========================================
Files 823 823
Lines 15147 15162 +15
Branches 4379 4381 +2
==========================================
+ Hits 14961 14971 +10
- Misses 179 183 +4
- Partials 7 8 +1
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## main #4100 +/- ##
==========================================
- Coverage 98.77% 98.74% -0.04%
==========================================
Files 823 823
Lines 15147 15162 +15
Branches 4387 4381 -6
==========================================
+ Hits 14961 14971 +10
- Misses 179 183 +4
- Partials 7 8 +1
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
Description
This PR addresses a
SyntaxErrorwhere the browser attempts to import a minified export (e.g., 'C') from a JavaScript chunk, but the chunk served by the CDN no longer provides that export under the expected name. This typically occurs when a user's browser has a stale cached entry bundle or lazy-loaded chunk after a new deployment, leading to a version mismatch.Root Cause: Vite/Rollup's minification process can change the single-letter names assigned to exports in JavaScript chunks across different builds, even if the source code for that specific chunk hasn't changed. If a user's browser loads an older, cached importer chunk that expects a specific minified export name (like 'C'), but the CDN serves a newer version of the target chunk where that export has a different minified name, a
SyntaxErroroccurs.Solution:
Implemented a
lazyWithRetryhelper function that wrapsReact.lazycalls. This helper catches chunk loading errors, specificallySyntaxErrorinstances that indicate a missing export. If such an error occurs and the page has not already been force-reloaded (checked viasessionStorageto prevent infinite loops), it triggers awindow.location.reload(). This forces the browser to fetch the latestindex.htmland all associated content-hashed JavaScript bundles, resolving the version mismatch. This ensures that users encountering stale-chunk errors are gracefully recovered with a hard refresh, preventing the application from breaking.Code Example
Notable Changes
lazyWithRetryhelper function to wrapReact.lazycalls.SyntaxErrorduring dynamic chunk loading.sessionStorageto track if a force-reload has already occurred, preventing infinite reload loops.window.location.reload()upon detecting a stale chunkSyntaxErrorto force a full page refresh and fetch the latest bundles.Screenshots
N/A
Link to Sample Entry
N/A
Legal Boilerplate
Look, I get it. The entity doing business as "Codecov" is owned by Harness, Inc. In 2026 Harness acquired Codecov and as a result Harness is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Harness can use, modify, copy, and redistribute my contributions, under Harness's choice of terms.
Fixes GAZEBO-1866
This PR was automatically generated by Sentry. You can adjust this setting at any time.