Skip to content

The open alternative to Salesforce, designed for AI.

Fix front-component cache read rejection bypassing network fallback (#22785)

Paul Rastoin05afc49ea64c
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 ff3ca7e9c2a..66ca4563451 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 8884cfb06d8..242e9765570 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;
}