From 979a2612bb56071f0690320c698452aefb4065ca Mon Sep 17 00:00:00 2001 From: Ragnar Rognstad Date: Mon, 16 Dec 2024 12:20:51 +0100 Subject: [PATCH 1/4] fix cloudflare adapter with svelte --- packages/cloudflare/src/index.ts | 10 +++++++--- .../with-svelte/src/components/Component.svelte | 4 ++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/cloudflare/src/index.ts b/packages/cloudflare/src/index.ts index 3193683c2..cde231deb 100644 --- a/packages/cloudflare/src/index.ts +++ b/packages/cloudflare/src/index.ts @@ -12,7 +12,7 @@ import { import { createRedirectsFromAstroRoutes } from '@astrojs/underscore-redirects'; import astroWhen from '@inox-tools/astro-when'; import { AstroError } from 'astro/errors'; -import { defaultClientConditions } from 'vite'; +import { defaultServerConditions } from 'vite'; import { type GetPlatformProxyOptions, getPlatformProxy } from 'wrangler'; import { type CloudflareModulePluginExtra, @@ -219,11 +219,15 @@ export default function createIntegration(args?: Options): AstroIntegration { } } - // Support `workerd` and `worker` conditions for the ssr environment + // Support `workerd` and `worker` conditions for the ssr environment + // while also removing the `node` condition to prevent node specific imports // (previously supported in esbuild instead: https://github.com/withastro/astro/pull/7092) vite.ssr ||= {}; vite.ssr.resolve ||= {}; - vite.ssr.resolve.conditions ||= [...defaultClientConditions]; + vite.ssr.resolve.conditions ||= [...defaultServerConditions]; + vite.ssr.resolve.conditions = vite.ssr.resolve.conditions.filter( + (condition) => condition !== 'node' + ); vite.ssr.resolve.conditions.push('workerd', 'worker'); vite.ssr.target = 'webworker'; diff --git a/packages/cloudflare/test/fixtures/with-svelte/src/components/Component.svelte b/packages/cloudflare/test/fixtures/with-svelte/src/components/Component.svelte index a8a85aeb4..896b18f20 100644 --- a/packages/cloudflare/test/fixtures/with-svelte/src/components/Component.svelte +++ b/packages/cloudflare/test/fixtures/with-svelte/src/components/Component.svelte @@ -1 +1,5 @@ +
Svelte Content
From d0511260f242739f78fed911e92431bce9363286 Mon Sep 17 00:00:00 2001 From: Ragnar Rognstad Date: Mon, 16 Dec 2024 12:42:16 +0100 Subject: [PATCH 2/4] add onMount as well to the test --- .../fixtures/with-svelte/src/components/Component.svelte | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/cloudflare/test/fixtures/with-svelte/src/components/Component.svelte b/packages/cloudflare/test/fixtures/with-svelte/src/components/Component.svelte index 896b18f20..c061eba61 100644 --- a/packages/cloudflare/test/fixtures/with-svelte/src/components/Component.svelte +++ b/packages/cloudflare/test/fixtures/with-svelte/src/components/Component.svelte @@ -1,5 +1,9 @@
Svelte Content
From 02cac7200113d59e7bd62e628f056bcd51b802a3 Mon Sep 17 00:00:00 2001 From: Ragnar Rognstad Date: Mon, 16 Dec 2024 12:42:26 +0100 Subject: [PATCH 3/4] add changeset --- .changeset/gorgeous-grapes-occur.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/gorgeous-grapes-occur.md diff --git a/.changeset/gorgeous-grapes-occur.md b/.changeset/gorgeous-grapes-occur.md new file mode 100644 index 000000000..839c46693 --- /dev/null +++ b/.changeset/gorgeous-grapes-occur.md @@ -0,0 +1,5 @@ +--- +'@astrojs/cloudflare': patch +--- + +Fixes a bug where svelte were not working while using the Cloudflare adapter From 7ed44606e3bf799722a5c80df68d057a8dd3d3c4 Mon Sep 17 00:00:00 2001 From: Ragnar Rognstad Date: Mon, 16 Dec 2024 18:54:53 +0100 Subject: [PATCH 4/4] Fix wording in changeset --- .changeset/gorgeous-grapes-occur.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/gorgeous-grapes-occur.md b/.changeset/gorgeous-grapes-occur.md index 839c46693..b7bdb396a 100644 --- a/.changeset/gorgeous-grapes-occur.md +++ b/.changeset/gorgeous-grapes-occur.md @@ -2,4 +2,4 @@ '@astrojs/cloudflare': patch --- -Fixes a bug where svelte were not working while using the Cloudflare adapter +Fixes a bug where Svelte was not working properly when using the Cloudflare adapter