diff --git a/packages/twenty-front-component-renderer/src/remote/worker/utils/__tests__/fetchComponentSource.spec.ts b/packages/twenty-front-component-renderer/src/remote/worker/utils/__tests__/fetchComponentSource.spec.ts index ff3ca7e9c2..66ca456345 100644 --- a/packages/twenty-front-component-renderer/src/remote/worker/utils/__tests__/fetchComponentSource.spec.ts +++ b/packages/twenty-front-component-renderer/src/remote/worker/utils/__tests__/fetchComponentSource.spec.ts @@ -161,6 +161,29 @@ describe('fetchComponentSource', () => { expect(fetchMock).toHaveBeenCalledTimes(1); }); + it('falls back to the network when the cached response body is unreadable', async () => { + const cache = new FakeCache(); + + setupCaches(cache); + + cache.match.mockResolvedValueOnce({ + text: async () => { + throw new Error('body unreadable'); + }, + }); + + const fetchMock = jest.fn(async () => + createFakeJsResponse(COMPONENT_SOURCE), + ); + + globalThis.fetch = fetchMock as unknown as typeof fetch; + + const source = await fetchComponentSource({ url: FINGERPRINTED_URL }); + + expect(source).toBe(COMPONENT_SOURCE); + expect(fetchMock).toHaveBeenCalledTimes(1); + }); + it('does not cache a network response whose checksum does not match the URL', async () => { const cache = new FakeCache(); diff --git a/packages/twenty-front-component-renderer/src/remote/worker/utils/frontComponentCacheStorageService.ts b/packages/twenty-front-component-renderer/src/remote/worker/utils/frontComponentCacheStorageService.ts index 8884cfb06d..242e976557 100644 --- a/packages/twenty-front-component-renderer/src/remote/worker/utils/frontComponentCacheStorageService.ts +++ b/packages/twenty-front-component-renderer/src/remote/worker/utils/frontComponentCacheStorageService.ts @@ -48,7 +48,9 @@ export const frontComponentCacheStorageService = { try { const cachedResponse = await cache.match(url); - return isDefined(cachedResponse) ? cachedResponse.text() : undefined; + return isDefined(cachedResponse) + ? await cachedResponse.text() + : undefined; } catch { return undefined; }