From 9fc2ab8cc848739a21bfa3f754e9bec4926dc034 Mon Sep 17 00:00:00 2001 From: Jacob Jenkins Date: Thu, 14 Nov 2024 15:31:51 +0000 Subject: [PATCH] Update to svelte 5 (#12364) Co-authored-by: bluwy --- .changeset/five-dolls-smash.md | 20 ++ .changeset/tasty-coats-repair.md | 5 + examples/framework-multiple/package.json | 2 +- .../components/svelte/SvelteCounter.svelte | 15 +- examples/framework-svelte/package.json | 2 +- .../src/components/Counter.svelte | 15 +- examples/ssr/package.json | 2 +- examples/ssr/src/components/AddToCart.svelte | 5 +- examples/ssr/src/components/Cart.svelte | 4 +- .../e2e/fixtures/client-only/package.json | 2 +- .../components/svelte/SvelteCounter.svelte | 11 +- .../astro/e2e/fixtures/errors/package.json | 2 +- .../svelte/SvelteRuntimeError.svelte | 2 +- .../fixtures/multiple-frameworks/package.json | 2 +- .../components/svelte/SvelteCounter.svelte | 10 +- .../fixtures/nested-in-preact/package.json | 2 +- .../components/svelte/SvelteCounter.svelte | 11 +- .../e2e/fixtures/nested-in-react/package.json | 2 +- .../components/svelte/SvelteCounter.svelte | 11 +- .../e2e/fixtures/nested-in-solid/package.json | 2 +- .../components/svelte/SvelteCounter.svelte | 11 +- .../fixtures/nested-in-svelte/package.json | 2 +- .../components/svelte/SvelteCounter.svelte | 11 +- .../e2e/fixtures/nested-in-vue/package.json | 2 +- .../components/svelte/SvelteCounter.svelte | 11 +- .../fixtures/nested-recursive/package.json | 2 +- .../components/svelte/SvelteCounter.svelte | 11 +- .../fixtures/svelte-component/package.json | 2 +- .../src/components/Counter.svelte | 17 +- .../src/components/Stuff.svelte | 4 +- .../src/components/SvelteComponent.svelte | 2 +- .../src/components/ToggleSlots.svelte | 4 +- .../fixtures/view-transitions/package.json | 8 +- .../src/components/SvelteCounter.svelte | 10 +- .../astro/test/fixtures/0-css/package.json | 2 +- .../test/fixtures/0-css/svelte.config.mjs | 5 + .../alias-tsconfig-baseurl-only/package.json | 2 +- .../test/fixtures/alias-tsconfig/package.json | 2 +- .../astro/test/fixtures/alias/package.json | 2 +- .../test/fixtures/astro-children/package.json | 2 +- .../src/components/Component.svelte | 6 +- .../fixtures/astro-client-only/package.json | 2 +- .../src/components/PersistentCounter.svelte | 8 +- .../PersistentCounterStandalone.svelte | 8 +- .../test/fixtures/astro-dynamic/package.json | 2 +- .../src/components/PersistentCounter.svelte | 8 +- .../src/components/SvelteCounter.svelte | 10 +- .../fixtures/astro-markdown/astro.config.mjs | 6 +- .../test/fixtures/astro-markdown/package.json | 1 - .../src/components/Counter.svelte | 5 - .../fixtures/astro-slots-nested/package.json | 2 +- .../component-library-shared/Counter.svelte | 9 +- .../fixtures/component-library/package.json | 2 +- .../css-dangling-references/package.json | 2 +- .../src/components/Wrapper.svelte | 3 +- .../astro/test/fixtures/fetch/package.json | 2 +- packages/astro/test/fixtures/jsx/package.json | 2 +- .../jsx/src/components/SvelteCounter.svelte | 6 +- .../astro/test/fixtures/postcss/package.json | 2 +- .../server-islands/hybrid/package.json | 2 +- .../fixtures/server-islands/ssr/package.json | 2 +- .../test/fixtures/slots-svelte/package.json | 2 +- .../src/components/Counter.svelte | 8 +- .../fixtures/svelte-component/package.json | 2 +- .../src/components/TypeScript.svelte | 2 +- .../vue-with-multi-renderer/package.json | 2 +- packages/astro/test/postcss.test.js | 6 +- packages/integrations/solid/src/server.ts | 4 + packages/integrations/svelte/client-v5.js | 60 ----- packages/integrations/svelte/client.js | 125 --------- packages/integrations/svelte/client.svelte.js | 79 ++++++ packages/integrations/svelte/package.json | 18 +- packages/integrations/svelte/server-v5.d.ts | 2 - packages/integrations/svelte/server-v5.js | 57 ---- packages/integrations/svelte/server.js | 48 +++- packages/integrations/svelte/src/index.ts | 99 +------ pnpm-lock.yaml | 252 +++++++++--------- 77 files changed, 459 insertions(+), 636 deletions(-) create mode 100644 .changeset/five-dolls-smash.md create mode 100644 .changeset/tasty-coats-repair.md create mode 100644 packages/astro/test/fixtures/0-css/svelte.config.mjs delete mode 100644 packages/astro/test/fixtures/astro-markdown/src/components/Counter.svelte delete mode 100644 packages/integrations/svelte/client-v5.js delete mode 100644 packages/integrations/svelte/client.js create mode 100644 packages/integrations/svelte/client.svelte.js delete mode 100644 packages/integrations/svelte/server-v5.d.ts delete mode 100644 packages/integrations/svelte/server-v5.js diff --git a/.changeset/five-dolls-smash.md b/.changeset/five-dolls-smash.md new file mode 100644 index 000000000000..ad5e83fd9a84 --- /dev/null +++ b/.changeset/five-dolls-smash.md @@ -0,0 +1,20 @@ +--- +'@astrojs/svelte': major +--- + +Adds support for Svelte 5. Svelte 3 and 4 are no longer supported. + +The integration will now also no longer add `vitePreprocess()` by default if a preprocessor is not set up in `svelte.config.js`. It is recommended to set up the Svelte config manually so that features like IDE completion and syntax highlighting work properly. + +If you're using SCSS, Stylus, etc in your Svelte component style tags, make sure that the preprocessor is also set up in `svelte.config.js`. For example: + +```js +// svelte.config.js +import { vitePreprocess } from '@astrojs/svelte'; + +export default { + preprocess: vitePreprocess(), +}; +``` + +Refer to the [Svelte 5 migration guide](https://svelte.dev/docs/svelte/v5-migration-guide) and [`@sveltejs/vite-plugin-svelte` changelog](https://github.com/sveltejs/vite-plugin-svelte/blob/main/packages/vite-plugin-svelte/CHANGELOG.md#400) for details of their respective breaking changes. diff --git a/.changeset/tasty-coats-repair.md b/.changeset/tasty-coats-repair.md new file mode 100644 index 000000000000..10b97e1c3d45 --- /dev/null +++ b/.changeset/tasty-coats-repair.md @@ -0,0 +1,5 @@ +--- +'@astrojs/solid-js': patch +--- + +Handles checking Svelte 5 component functions to avoid processing them as Solid components diff --git a/examples/framework-multiple/package.json b/examples/framework-multiple/package.json index 1e63e0247928..fa0af0805e23 100644 --- a/examples/framework-multiple/package.json +++ b/examples/framework-multiple/package.json @@ -23,7 +23,7 @@ "react": "^18.3.1", "react-dom": "^18.3.1", "solid-js": "^1.9.3", - "svelte": "^4.2.19", + "svelte": "^5.1.16", "vue": "^3.5.12" } } diff --git a/examples/framework-multiple/src/components/svelte/SvelteCounter.svelte b/examples/framework-multiple/src/components/svelte/SvelteCounter.svelte index 01e58574a6ec..641312ae1b9f 100644 --- a/examples/framework-multiple/src/components/svelte/SvelteCounter.svelte +++ b/examples/framework-multiple/src/components/svelte/SvelteCounter.svelte @@ -2,7 +2,14 @@ A counter written with Svelte -->
- +
{count}
- +
- + {@render children?.()}
diff --git a/examples/framework-svelte/package.json b/examples/framework-svelte/package.json index 9c1adf7cf9c6..779267dd64ba 100644 --- a/examples/framework-svelte/package.json +++ b/examples/framework-svelte/package.json @@ -13,6 +13,6 @@ "dependencies": { "@astrojs/svelte": "^5.7.3", "astro": "^4.16.12", - "svelte": "^4.2.19" + "svelte": "^5.1.16" } } diff --git a/examples/framework-svelte/src/components/Counter.svelte b/examples/framework-svelte/src/components/Counter.svelte index 1353736aaab7..a11538645e6c 100644 --- a/examples/framework-svelte/src/components/Counter.svelte +++ b/examples/framework-svelte/src/components/Counter.svelte @@ -1,5 +1,12 @@
- +
{count}
- +
- + {@render children?.()}
- diff --git a/examples/ssr/src/components/Cart.svelte b/examples/ssr/src/components/Cart.svelte index 74db0bc7947c..5d4b7d2510c1 100644 --- a/examples/ssr/src/components/Cart.svelte +++ b/examples/ssr/src/components/Cart.svelte @@ -1,5 +1,5 @@
- +
{ count }
- +
- + {@render children?.()}
diff --git a/packages/astro/e2e/fixtures/errors/package.json b/packages/astro/e2e/fixtures/errors/package.json index 3730d61f1bd0..77c40677853c 100644 --- a/packages/astro/e2e/fixtures/errors/package.json +++ b/packages/astro/e2e/fixtures/errors/package.json @@ -14,7 +14,7 @@ "react-dom": "^18.3.1", "sass": "^1.80.6", "solid-js": "^1.9.3", - "svelte": "^4.2.19", + "svelte": "^5.1.16", "vue": "^3.5.12" } } diff --git a/packages/astro/e2e/fixtures/errors/src/components/svelte/SvelteRuntimeError.svelte b/packages/astro/e2e/fixtures/errors/src/components/svelte/SvelteRuntimeError.svelte index 54dbab6a7540..69d62a884f73 100644 --- a/packages/astro/e2e/fixtures/errors/src/components/svelte/SvelteRuntimeError.svelte +++ b/packages/astro/e2e/fixtures/errors/src/components/svelte/SvelteRuntimeError.svelte @@ -1,5 +1,5 @@
- +
{ count }
- +
- + {@render children?.()}
- +
{ count }
- +
diff --git a/packages/astro/test/fixtures/astro-client-only/src/components/PersistentCounterStandalone.svelte b/packages/astro/test/fixtures/astro-client-only/src/components/PersistentCounterStandalone.svelte index c851a42f86c6..cb2d5149649f 100644 --- a/packages/astro/test/fixtures/astro-client-only/src/components/PersistentCounterStandalone.svelte +++ b/packages/astro/test/fixtures/astro-client-only/src/components/PersistentCounterStandalone.svelte @@ -1,8 +1,8 @@
- +
{ count }
- +
\ No newline at end of file diff --git a/packages/astro/test/fixtures/astro-dynamic/src/components/SvelteCounter.svelte b/packages/astro/test/fixtures/astro-dynamic/src/components/SvelteCounter.svelte index 8d6b3f5e1688..d4972b7f92a8 100644 --- a/packages/astro/test/fixtures/astro-dynamic/src/components/SvelteCounter.svelte +++ b/packages/astro/test/fixtures/astro-dynamic/src/components/SvelteCounter.svelte @@ -1,7 +1,7 @@
- +
{ count }
- +
- + {@render children?.()}
diff --git a/packages/astro/test/fixtures/astro-markdown/astro.config.mjs b/packages/astro/test/fixtures/astro-markdown/astro.config.mjs index ac3f1ab6439e..201ce52f26ef 100644 --- a/packages/astro/test/fixtures/astro-markdown/astro.config.mjs +++ b/packages/astro/test/fixtures/astro-markdown/astro.config.mjs @@ -1,8 +1,6 @@ -import svelte from "@astrojs/svelte"; -import { defineConfig } from 'astro/config'; +import { defineConfig } from "astro/config"; // https://astro.build/config export default defineConfig({ - integrations: [svelte()], - site: 'https://astro.build/', + site: "https://astro.build/", }); diff --git a/packages/astro/test/fixtures/astro-markdown/package.json b/packages/astro/test/fixtures/astro-markdown/package.json index c1903a941ea1..9fe9dae0124d 100644 --- a/packages/astro/test/fixtures/astro-markdown/package.json +++ b/packages/astro/test/fixtures/astro-markdown/package.json @@ -3,7 +3,6 @@ "version": "0.0.0", "private": true, "dependencies": { - "@astrojs/svelte": "workspace:*", "astro": "workspace:*" } } diff --git a/packages/astro/test/fixtures/astro-markdown/src/components/Counter.svelte b/packages/astro/test/fixtures/astro-markdown/src/components/Counter.svelte deleted file mode 100644 index 4e91b26596c4..000000000000 --- a/packages/astro/test/fixtures/astro-markdown/src/components/Counter.svelte +++ /dev/null @@ -1,5 +0,0 @@ - - - diff --git a/packages/astro/test/fixtures/astro-slots-nested/package.json b/packages/astro/test/fixtures/astro-slots-nested/package.json index 114e369d6cd6..6d541872ec11 100644 --- a/packages/astro/test/fixtures/astro-slots-nested/package.json +++ b/packages/astro/test/fixtures/astro-slots-nested/package.json @@ -13,7 +13,7 @@ "react": "^18.3.1", "react-dom": "^18.3.1", "solid-js": "^1.9.3", - "svelte": "^4.2.19", + "svelte": "^5.1.16", "vue": "^3.5.12" } } diff --git a/packages/astro/test/fixtures/component-library-shared/Counter.svelte b/packages/astro/test/fixtures/component-library-shared/Counter.svelte index 2f4c07339060..0ca9f08b0d96 100644 --- a/packages/astro/test/fixtures/component-library-shared/Counter.svelte +++ b/packages/astro/test/fixtures/component-library-shared/Counter.svelte @@ -1,5 +1,6 @@
- +
{ count }
- +
- + {@render children?.()}