From 180c2ae9f64cf296504ec3440939f920b308f258 Mon Sep 17 00:00:00 2001 From: Marcos Perona Date: Fri, 1 Dec 2023 15:54:04 +0000 Subject: [PATCH 1/3] fix: polyfill also when shimmed --- packages/qwik-city/middleware/cloudflare-pages/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/qwik-city/middleware/cloudflare-pages/index.ts b/packages/qwik-city/middleware/cloudflare-pages/index.ts index ab033bd6185..b9a3a335b12 100644 --- a/packages/qwik-city/middleware/cloudflare-pages/index.ts +++ b/packages/qwik-city/middleware/cloudflare-pages/index.ts @@ -15,7 +15,9 @@ import { setServerPlatform } from '@builder.io/qwik/server'; /** @public */ export function createQwikCity(opts: QwikCityCloudflarePagesOptions) { - if (typeof globalThis.TextEncoderStream === 'undefined') { + try { + new globalThis.TextEncoderStream(); + } catch (e) { (globalThis as any).TextEncoderStream = TextEncoderStream; } const qwikSerializer = { From 9160f9b75944342d4a18faafd1efb84f76c3a2cc Mon Sep 17 00:00:00 2001 From: Marcos Perona Date: Fri, 1 Dec 2023 16:43:57 +0000 Subject: [PATCH 2/3] chore: add comment to explain polyfill --- packages/qwik-city/middleware/cloudflare-pages/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/qwik-city/middleware/cloudflare-pages/index.ts b/packages/qwik-city/middleware/cloudflare-pages/index.ts index b9a3a335b12..7f3f0b75371 100644 --- a/packages/qwik-city/middleware/cloudflare-pages/index.ts +++ b/packages/qwik-city/middleware/cloudflare-pages/index.ts @@ -16,6 +16,7 @@ import { setServerPlatform } from '@builder.io/qwik/server'; /** @public */ export function createQwikCity(opts: QwikCityCloudflarePagesOptions) { try { + // this will throw if CF compatibility_date < 2022-11-30 new globalThis.TextEncoderStream(); } catch (e) { (globalThis as any).TextEncoderStream = TextEncoderStream; From fa4709c3398f502dba0b9fe4d3834a0c6f66b5c3 Mon Sep 17 00:00:00 2001 From: Marcos Perona Date: Fri, 1 Dec 2023 16:48:34 +0000 Subject: [PATCH 3/3] chore: Giorgio's feedback --- packages/qwik-city/middleware/cloudflare-pages/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/qwik-city/middleware/cloudflare-pages/index.ts b/packages/qwik-city/middleware/cloudflare-pages/index.ts index 7f3f0b75371..9a00ff789e0 100644 --- a/packages/qwik-city/middleware/cloudflare-pages/index.ts +++ b/packages/qwik-city/middleware/cloudflare-pages/index.ts @@ -16,6 +16,7 @@ import { setServerPlatform } from '@builder.io/qwik/server'; /** @public */ export function createQwikCity(opts: QwikCityCloudflarePagesOptions) { try { + // https://developers.cloudflare.com/workers/configuration/compatibility-dates/#streams-constructors // this will throw if CF compatibility_date < 2022-11-30 new globalThis.TextEncoderStream(); } catch (e) {