fix(ios): verify the shell before saving offline trips

Recheck cached assets during explicit offline preparation even when the build is marked warm. Keep the existing start page, trip cache, and pin if this check fails. Keep the ordinary launch fast path for warm builds.

Refs #3318
This commit is contained in:
Maurice
2026-12-05 12:35:18 +01:00
parent 06ee5a850b
commit b79d104349
6 changed files with 79 additions and 27 deletions
+33 -7
View File
@@ -38,7 +38,7 @@ describe('manifestFiles', () => {
});
describe('keepOfflineShellFresh', () => {
it('refreshes the stored start page and fetches every file of the build', async () => {
it('tries every asset even when one fails and does not replace the stored start page', async () => {
const fetched: string[] = [];
const fetchImpl = vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
const url = String(input);
@@ -53,7 +53,7 @@ describe('keepOfflineShellFresh', () => {
await keepOfflineShellFresh(fetchImpl);
expect(TrekShell.refreshOfflineCopy).toHaveBeenCalled();
expect(TrekShell.refreshOfflineCopy).not.toHaveBeenCalled();
expect(fetched.sort()).toEqual([
'/assets/AtlasPage-99887766.js',
'/assets/index-a1b2c3d4.js',
@@ -63,10 +63,11 @@ describe('keepOfflineShellFresh', () => {
]);
});
it('stops after the start page when the build has no manifest', async () => {
it('keeps the previous start page when the build has no manifest', async () => {
const fetchImpl = vi.fn(async () => new Response('', { status: 404 })) as unknown as typeof fetch;
await keepOfflineShellFresh(fetchImpl);
expect(fetchImpl).toHaveBeenCalledTimes(1);
expect(TrekShell.refreshOfflineCopy).not.toHaveBeenCalled();
});
it('fetches at low priority, only the own language, and once per build', async () => {
@@ -114,6 +115,31 @@ describe('keepOfflineShellFresh', () => {
expect(fetchImpl).toHaveBeenCalledWith('/assets/AtlasPage-99887766.js', { priority: 'low' });
});
it('rechecks the marked iOS shell on demand and keeps the previous start page if an asset is missing', async () => {
const chunk = '/assets/AtlasPage-99887766.js';
let chunkAvailable = true;
const fetchImpl = vi.fn(async (input: RequestInfo | URL) => {
if (String(input) === '/asset-manifest.json') return new Response(JSON.stringify(manifest));
if (String(input) === chunk && !chunkAvailable) return new Response(null, { status: 503 });
return new Response('asset');
});
expect(await keepOfflineShellFresh(fetchImpl)).toBe(true);
expect(await keepOfflineShellFresh(fetchImpl)).toBe(true);
expect(fetchImpl.mock.calls.filter(([url]) => url === chunk)).toHaveLength(1);
vi.mocked(TrekShell.refreshOfflineCopy).mockClear();
chunkAvailable = false;
expect(await keepOfflineShellFresh(fetchImpl, 'en', { verifyAssets: true })).toBe(false);
expect(fetchImpl.mock.calls.filter(([url]) => url === chunk)).toHaveLength(2);
expect(TrekShell.refreshOfflineCopy).not.toHaveBeenCalled();
chunkAvailable = true;
expect(await keepOfflineShellFresh(fetchImpl)).toBe(true);
expect(fetchImpl.mock.calls.filter(([url]) => url === chunk)).toHaveLength(3);
expect(TrekShell.refreshOfflineCopy).toHaveBeenCalledOnce();
});
it('on Android hands the list to the native store instead of fetching it here', async () => {
vi.mocked(TrekShell.refreshOfflineCopy).mockResolvedValue({ saved: true, complete: true });
const fetchImpl = vi.fn(async (input: RequestInfo | URL) => {
@@ -121,7 +147,7 @@ describe('keepOfflineShellFresh', () => {
throw new Error('the native side fetches the files');
}) as unknown as typeof fetch;
await keepOfflineShellFresh(fetchImpl, 'en', true);
await keepOfflineShellFresh(fetchImpl, 'en', { nativeStore: true });
expect(fetchImpl).toHaveBeenCalledTimes(1);
expect(TrekShell.refreshOfflineCopy).toHaveBeenCalledTimes(1);
@@ -142,7 +168,7 @@ describe('keepOfflineShellFresh', () => {
const fetchImpl = vi.fn(async () => new Response(JSON.stringify(manifest))) as unknown as typeof fetch;
try {
await keepOfflineShellFresh(fetchImpl, 'en', true);
await keepOfflineShellFresh(fetchImpl, 'en', { nativeStore: true });
} finally {
document.head.innerHTML = '';
}
@@ -158,8 +184,8 @@ describe('keepOfflineShellFresh', () => {
vi.mocked(TrekShell.refreshOfflineCopy).mockResolvedValue({ saved: true, complete: false });
const fetchImpl = vi.fn(async () => new Response(JSON.stringify(manifest))) as unknown as typeof fetch;
await keepOfflineShellFresh(fetchImpl, 'en', true);
await keepOfflineShellFresh(fetchImpl, 'en', true);
await keepOfflineShellFresh(fetchImpl, 'en', { nativeStore: true });
await keepOfflineShellFresh(fetchImpl, 'en', { nativeStore: true });
expect(TrekShell.refreshOfflineCopy).toHaveBeenCalledTimes(2);
});