mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 19:40:34 +00:00
fix(native): first visits no longer wait behind the offline warm-up, day rail follows the swipe
The iOS app pulls every file of a build into WebKit's cache so it can start offline. It did so four at a time at normal priority, for all 1,900 files of every new build including all 27 translations, and a page opened meanwhile queued behind it: right after a server update, a first visit to Vacay took five to seven seconds. The warm-up now runs two at a time at low priority, takes only the user's language and English, and walks a build once. The day rail in the trip header lit the new day only after the pager's snap had landed and the plan had re-rendered, a second or two after the swipe. The pager now reports the day a swipe heads for as soon as its page is the nearer one, and the rail and its pill move with the finger; the plan still switches when the snap lands.
This commit is contained in:
@@ -17,6 +17,7 @@ const manifest = {
|
||||
|
||||
beforeEach(() => {
|
||||
vi.mocked(TrekShell.refreshOfflineCopy).mockReset().mockResolvedValue({ saved: true });
|
||||
window.localStorage.clear();
|
||||
});
|
||||
|
||||
describe('manifestFiles', () => {
|
||||
@@ -67,4 +68,35 @@ describe('keepOfflineShellFresh', () => {
|
||||
await keepOfflineShellFresh(fetchImpl);
|
||||
expect(fetchImpl).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('fetches at low priority, only the own language, and once per build', async () => {
|
||||
const withLocales = {
|
||||
...manifest,
|
||||
'../shared/dist/i18n/de/index.mjs': { file: 'assets/de-aaaa1111.js' },
|
||||
'../shared/dist/i18n/fr/index.mjs': { file: 'assets/fr-bbbb2222.js' },
|
||||
'../shared/dist/i18n/en/index.mjs': { file: 'assets/en-cccc3333.js' },
|
||||
};
|
||||
const inits: (RequestInit | undefined)[] = [];
|
||||
const fetched: string[] = [];
|
||||
const fetchImpl = vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
|
||||
const url = String(input);
|
||||
if (url === '/asset-manifest.json') return new Response(JSON.stringify(withLocales));
|
||||
fetched.push(url);
|
||||
inits.push(init);
|
||||
return new Response('x');
|
||||
}) as unknown as typeof fetch;
|
||||
|
||||
await keepOfflineShellFresh(fetchImpl, 'de');
|
||||
expect(fetched).toContain('/assets/de-aaaa1111.js');
|
||||
expect(fetched).toContain('/assets/en-cccc3333.js');
|
||||
expect(fetched).not.toContain('/assets/fr-bbbb2222.js');
|
||||
expect(inits.every((i) => (i as { priority?: string } | undefined)?.priority === 'low')).toBe(true);
|
||||
|
||||
const before = fetched.length;
|
||||
await keepOfflineShellFresh(fetchImpl, 'de');
|
||||
expect(fetched.length).toBe(before);
|
||||
|
||||
await keepOfflineShellFresh(fetchImpl, 'fr');
|
||||
expect(fetched).toContain('/assets/fr-bbbb2222.js');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user