mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 21:33:19 +00:00
fix(client): five loads that catch their own error recover from a deploy too
The PDF export on desktop and phone, the language switch, the holiday regions and the PDF's map image load a chunk on demand and catch the failure themselves. After a deploy the old page asks for chunk names the new build no longer has, so they showed their own error on every retry (or, for the language, silently stayed in the old one) instead of reloading onto the new build the way an uncaught chunk error does. importChunk reloads once for a missing chunk and still hands the caller its error.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { isChunkLoadError, reloadOnceForChunk, clearChunkReloadMarker, reloadFresh, FRESH_LOAD_PARAM } from './chunkReload';
|
||||
import { isChunkLoadError, reloadOnceForChunk, clearChunkReloadMarker, reloadFresh, importChunk, FRESH_LOAD_PARAM } from './chunkReload';
|
||||
|
||||
const net = vi.hoisted(() => ({
|
||||
probeNow: vi.fn(async () => 'online' as 'online' | 'offline' | 'proxy-wall'),
|
||||
@@ -83,6 +83,18 @@ describe('reloadFresh', () => {
|
||||
describe('reloadOnceForChunk', () => {
|
||||
const stubReload = () => stubLocation().reload;
|
||||
|
||||
it('FE-UTIL-CHUNK-020: importChunk reloads once for a chunk the deploy removed, and still hands the caller the error', async () => {
|
||||
const reload = stubReload();
|
||||
const gone = new TypeError('Failed to fetch dynamically imported module: /assets/TripPDF-abc123.js');
|
||||
await expect(importChunk(() => Promise.reject(gone))).rejects.toBe(gone);
|
||||
expect(reload).toHaveBeenCalledTimes(1);
|
||||
|
||||
// Anything else is the caller's error alone.
|
||||
await expect(importChunk(() => Promise.reject(new Error('pdf layout failed')))).rejects.toThrow('pdf layout failed');
|
||||
expect(reload).toHaveBeenCalledTimes(1);
|
||||
await expect(importChunk(() => Promise.resolve({ ok: true }))).resolves.toEqual({ ok: true });
|
||||
});
|
||||
|
||||
it('FE-UTIL-CHUNK-004: reloads the first time and refuses afterwards', () => {
|
||||
const reload = stubReload();
|
||||
expect(reloadOnceForChunk()).toBe(true);
|
||||
|
||||
Reference in New Issue
Block a user