Skip to content

Commit

Permalink
Update to svelte 5 (#12364)
Browse files Browse the repository at this point in the history
Co-authored-by: bluwy <[email protected]>
  • Loading branch information
jdtjenkins and bluwy authored Nov 14, 2024
1 parent bdc0890 commit 9fc2ab8
Show file tree
Hide file tree
Showing 77 changed files with 459 additions and 636 deletions.
20 changes: 20 additions & 0 deletions .changeset/five-dolls-smash.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 5 additions & 0 deletions .changeset/tasty-coats-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/solid-js': patch
---

Handles checking Svelte 5 component functions to avoid processing them as Solid components
2 changes: 1 addition & 1 deletion examples/framework-multiple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
A counter written with Svelte
-->
<script lang="ts">
let count = 0;
import type { Snippet } from 'svelte';
interface Props {
children?: Snippet
}
let { children }: Props = $props();
let count = $state(0);
function add() {
count += 1;
Expand All @@ -14,10 +21,10 @@ A counter written with Svelte
</script>

<div class="counter">
<button on:click={subtract}>-</button>
<button onclick={subtract}>-</button>
<pre>{count}</pre>
<button on:click={add}>+</button>
<button onclick={add}>+</button>
</div>
<div class="counter-message">
<slot />
{@render children?.()}
</div>
2 changes: 1 addition & 1 deletion examples/framework-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"dependencies": {
"@astrojs/svelte": "^5.7.3",
"astro": "^4.16.12",
"svelte": "^4.2.19"
"svelte": "^5.1.16"
}
}
15 changes: 11 additions & 4 deletions examples/framework-svelte/src/components/Counter.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<script lang="ts">
let count = 0;
import type { Snippet } from 'svelte';
interface Props {
children?: Snippet
}
let { children }: Props = $props();
let count = $state(0);
function add() {
count += 1;
Expand All @@ -11,12 +18,12 @@
</script>

<div class="counter">
<button on:click={subtract}>-</button>
<button onclick={subtract}>-</button>
<pre>{count}</pre>
<button on:click={add}>+</button>
<button onclick={add}>+</button>
</div>
<div class="message">
<slot />
{@render children?.()}
</div>

<style>
Expand Down
2 changes: 1 addition & 1 deletion examples/ssr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"@astrojs/node": "^8.3.4",
"@astrojs/svelte": "^5.7.3",
"astro": "^4.16.12",
"svelte": "^4.2.19"
"svelte": "^5.1.16"
}
}
5 changes: 2 additions & 3 deletions examples/ssr/src/components/AddToCart.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script>
import { addToUserCart } from '../api';
export let id = 0;
export let name = '';
let { id, name } = $props()
function notifyCartItem(id) {
window.dispatchEvent(new CustomEvent('add-to-cart', {
Expand Down Expand Up @@ -49,6 +48,6 @@ button:hover {
text-transform: uppercase;
}
</style>
<button on:click={addToCart}>
<button click={addToCart}>
<span class="pretext">Add to cart</span>
</button>
4 changes: 2 additions & 2 deletions examples/ssr/src/components/Cart.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
export let count = 0;
let { count } = $props()
let items = new Set();
function onAddToCart(ev) {
Expand Down Expand Up @@ -27,7 +27,7 @@
font-size: 24px;
}
</style>
<svelte:window on:add-to-cart={onAddToCart}/>
<svelte:window onadd-to-cart={onAddToCart}/>
<a href="/cart" class="cart">
<span class="material-icons cart-icon">shopping_cart</span>
<span class="count">{count}</span>
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/fixtures/client-only/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,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"
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

<script>
export let id;
let children;
let count = 0;
let { id, children } = $props();
let count = $state(0);
function add() {
count += 1;
Expand All @@ -14,11 +13,11 @@
</script>

<div {id} class="counter">
<button class="decrement" on:click={subtract}>-</button>
<button class="decrement" onclick={subtract}>-</button>
<pre>{ count }</pre>
<button class="increment" on:click={add}>+</button>
<button class="increment" onclick={add}>+</button>
<div class="children">
<slot />
{@render children?.()}
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/fixtures/errors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
export let shouldThrow = true;
let { shouldThrow } = $props();
if (shouldThrow) {
throw new Error('SvelteRuntimeError');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,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"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

<script>
export let id;
let count = 0;
let { id, children } = $props();
let count = $state(0);
function add() {
count += 1;
Expand All @@ -13,12 +13,12 @@
</script>

<div {id} class="counter">
<button class="decrement" on:click={subtract}>-</button>
<button class="decrement" onclick={subtract}>-</button>
<pre>{ count }</pre>
<button class="increment" on:click={add}>+</button>
<button class="increment" onclick={add}>+</button>
</div>
<div class="counter-message">
<slot />
{@render children?.()}
</div>

<style>
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/fixtures/nested-in-preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,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"
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

<script>
export let id;
let children;
let count = 0;
let { id, children } = $props();
let count = $state(0);
function add() {
count += 1;
Expand All @@ -14,11 +13,11 @@
</script>

<div {id} class="counter">
<button class="decrement" on:click={subtract}>-</button>
<button class="decrement" onclick={subtract}>-</button>
<pre id={`${id}-count`}>{ count }</pre>
<button id={`${id}-increment`} class="increment" on:click={add}>+</button>
<button id={`${id}-increment`} class="increment" onclick={add}>+</button>
<div class="children">
<slot />
{@render children?.()}
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/fixtures/nested-in-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,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"
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

<script>
export let id;
let children;
let count = 0;
let { id, children } = $props();
let count = $state(0);
function add() {
count += 1;
Expand All @@ -14,11 +13,11 @@
</script>

<div {id} class="counter">
<button class="decrement" on:click={subtract}>-</button>
<button class="decrement" onclick={subtract}>-</button>
<pre id={`${id}-count`}>{ count }</pre>
<button id={`${id}-increment`} class="increment" on:click={add}>+</button>
<button id={`${id}-increment`} class="increment" onclick={add}>+</button>
<div class="children">
<slot />
{@render children?.()}
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/fixtures/nested-in-solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,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"
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

<script>
export let id;
let children;
let count = 0;
let { id, children } = $props();
let count = $state(0);
function add() {
count += 1;
Expand All @@ -14,11 +13,11 @@
</script>

<div {id} class="counter">
<button class="decrement" on:click={subtract}>-</button>
<button class="decrement" onclick={subtract}>-</button>
<pre id={`${id}-count`}>{ count }</pre>
<button id={`${id}-increment`} class="increment" on:click={add}>+</button>
<button id={`${id}-increment`} class="increment" onclick={add}>+</button>
<div class="children">
<slot />
{@render children?.()}
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/fixtures/nested-in-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,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"
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

<script>
export let id;
let children;
let count = 0;
let { id, children } = $props();
let count = $state(0);
function add() {
count += 1;
Expand All @@ -14,11 +13,11 @@
</script>

<div {id} class="counter">
<button class="decrement" on:click={subtract}>-</button>
<button class="decrement" onclick={subtract}>-</button>
<pre id={`${id}-count`}>{ count }</pre>
<button id={`${id}-increment`} class="increment" on:click={add}>+</button>
<button id={`${id}-increment`} class="increment" onclick={add}>+</button>
<div class="children">
<slot />
{@render children?.()}
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/fixtures/nested-in-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,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"
}
}
Loading

0 comments on commit 9fc2ab8

Please sign in to comment.