Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cloudflare): resolve conditions for svelte #487

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gorgeous-grapes-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/cloudflare': patch
---

Fixes a bug where Svelte was not working properly when using the Cloudflare adapter
10 changes: 7 additions & 3 deletions packages/cloudflare/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
<script>
import { setContext, onMount } from 'svelte';

setContext('svelte', true);
onMount(() => {
console.log('The component has mounted!');
});
</script>
<div class="svelte">Svelte Content</div>
Loading