diff --git a/.changeset/legal-mangos-peel.md b/.changeset/legal-mangos-peel.md deleted file mode 100644 index bddad21bff..0000000000 --- a/.changeset/legal-mangos-peel.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'svelte': patch ---- - -fix: change title only after any pending work has completed diff --git a/.changeset/sixty-comics-bow.md b/.changeset/sixty-comics-bow.md deleted file mode 100644 index 2463e52430..0000000000 --- a/.changeset/sixty-comics-bow.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'svelte': patch ---- - -fix: preserve symbols when creating derived rest properties diff --git a/.prettierignore b/.prettierignore index 9cf9a4bfe1..ee5ef6d8c6 100644 --- a/.prettierignore +++ b/.prettierignore @@ -25,6 +25,10 @@ packages/svelte/tests/**/_output packages/svelte/tests/**/shards/*.test.js packages/svelte/tests/hydration/samples/*/_expected.html packages/svelte/tests/hydration/samples/*/_override.html +packages/svelte/tests/parser-legacy/samples/*/_actual.json +packages/svelte/tests/parser-legacy/samples/*/output.json +packages/svelte/tests/parser-modern/samples/*/_actual.json +packages/svelte/tests/parser-modern/samples/*/output.json packages/svelte/types packages/svelte/compiler/index.js playgrounds/sandbox/src/* diff --git a/documentation/docs/01-introduction/02-getting-started.md b/documentation/docs/01-introduction/02-getting-started.md index 2ad22c8469..519959a0b1 100644 --- a/documentation/docs/01-introduction/02-getting-started.md +++ b/documentation/docs/01-introduction/02-getting-started.md @@ -23,9 +23,10 @@ There are also [plugins for other bundlers](/packages#bundler-plugins), but we r ## Editor tooling -The Svelte team maintains a [VS Code extension](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode), and there are integrations with various other [editors](https://sveltesociety.dev/resources#editor-support) and tools as well. +The Svelte team maintains a [VS Code extension](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode), and there are integrations with various other [editors](https://sveltesociety.dev/collection/editor-support-c85c080efc292a34) and tools as well. + +You can also check your code from the command line using [`sv check`](https://github.com/sveltejs/cli). -You can also check your code from the command line using [sv check](https://github.com/sveltejs/cli). ## Getting help diff --git a/documentation/docs/02-runes/06-$bindable.md b/documentation/docs/02-runes/06-$bindable.md index c12c2bf490..3675a56b16 100644 --- a/documentation/docs/02-runes/06-$bindable.md +++ b/documentation/docs/02-runes/06-$bindable.md @@ -4,7 +4,7 @@ title: $bindable Ordinarily, props go one way, from parent to child. This makes it easy to understand how data flows around your app. -In Svelte, component props can be _bound_, which means that data can also flow _up_ from child to parent. This isn't something you should do often, but it can simplify your code if used sparingly and carefully. +In Svelte, component props can be _bound_, which means that data can also flow _up_ from child to parent. This isn't something you should do often — overuse can make your data flow unpredictable and your components harder to maintain — but it can simplify your code if used sparingly and carefully. It also means that a state proxy can be _mutated_ in the child. diff --git a/documentation/docs/06-runtime/03-lifecycle-hooks.md b/documentation/docs/06-runtime/03-lifecycle-hooks.md index f7a78beec9..95e1c260c1 100644 --- a/documentation/docs/06-runtime/03-lifecycle-hooks.md +++ b/documentation/docs/06-runtime/03-lifecycle-hooks.md @@ -94,7 +94,7 @@ Svelte 4 contained hooks that ran before and after the component as a whole was ``` -Instead of `beforeUpdate` use `$effect.pre` and instead of `afterUpdate` use `$effect` instead - these runes offer more granular control and only react to the changes you're actually interested in. +Instead of `beforeUpdate` use `$effect.pre` and instead of `afterUpdate` use `$effect` instead — these runes offer more granular control and only react to the changes you're actually interested in. ### Chat window example diff --git a/documentation/docs/06-runtime/05-hydratable.md b/documentation/docs/06-runtime/05-hydratable.md new file mode 100644 index 0000000000..a5302f264d --- /dev/null +++ b/documentation/docs/06-runtime/05-hydratable.md @@ -0,0 +1,65 @@ +--- +title: Hydratable data +--- + +In Svelte, when you want to render asynchronous content data on the server, you can simply `await` it. This is great! However, it comes with a pitfall: when hydrating that content on the client, Svelte has to redo the asynchronous work, which blocks hydration for however long it takes: + +```svelte + + +

{user.name}

+``` + +That's silly, though. If we've already done the hard work of getting the data on the server, we don't want to get it again during hydration on the client. `hydratable` is a low-level API built to solve this problem. You probably won't need this very often — it will be used behind the scenes by whatever datafetching library you use. For example, it powers [remote functions in SvelteKit](/docs/kit/remote-functions). + +To fix the example above: + +```svelte + + +

{user.name}

+``` + +This API can also be used to provide access to random or time-based values that are stable between server rendering and hydration. For example, to get a random number that doesn't update on hydration: + +```ts +import { hydratable } from 'svelte'; +const rand = hydratable('random', () => Math.random()); +``` + +If you're a library author, be sure to prefix the keys of your `hydratable` values with the name of your library so that your keys don't conflict with other libraries. + +## Serialization + +All data returned from a `hydratable` function must be serializable. But this doesn't mean you're limited to JSON — Svelte uses [`devalue`](https://npmjs.com/package/devalue), which can serialize all sorts of things including `Map`, `Set`, `URL`, and `BigInt`. Check the documentation page for a full list. In addition to these, thanks to some Svelte magic, you can also fearlessly use promises: + +```svelte + + +{await promises.one} +{await promises.two} +``` diff --git a/documentation/docs/07-misc/02-testing.md b/documentation/docs/07-misc/02-testing.md index 4807fc8f0c..85db7fc01f 100644 --- a/documentation/docs/07-misc/02-testing.md +++ b/documentation/docs/07-misc/02-testing.md @@ -294,7 +294,7 @@ E2E (short for 'end to end') tests allow you to test your full application throu You can use the Svelte CLI to [setup Playwright](/docs/cli/playwright) either during project creation or later on. You can also [set it up with `npm init playwright`](https://playwright.dev/docs/intro). Additionally, you may also want to install an IDE plugin such as [the VS Code extension](https://playwright.dev/docs/getting-started-vscode) to be able to execute tests from inside your IDE. -If you've run `npm init playwright` or are not using Vite, you may need to adjust the Playwright config to tell Playwright what to do before running the tests - mainly starting your application at a certain port. For example: +If you've run `npm init playwright` or are not using Vite, you may need to adjust the Playwright config to tell Playwright what to do before running the tests — mainly starting your application at a certain port. For example: ```js /// file: playwright.config.js diff --git a/documentation/docs/07-misc/06-v4-migration-guide.md b/documentation/docs/07-misc/06-v4-migration-guide.md index 484931f20a..dbb1cac215 100644 --- a/documentation/docs/07-misc/06-v4-migration-guide.md +++ b/documentation/docs/07-misc/06-v4-migration-guide.md @@ -137,7 +137,7 @@ Transitions are now local by default to prevent confusion around page navigation {/if} ``` -To make transitions global, add the `|global` modifier - then they will play when _any_ control flow block above is created/destroyed. The migration script will do this automatically for you. ([#6686](https://github.com/sveltejs/svelte/issues/6686)) +To make transitions global, add the `|global` modifier — then they will play when _any_ control flow block above is created/destroyed. The migration script will do this automatically for you. ([#6686](https://github.com/sveltejs/svelte/issues/6686)) ## Default slot bindings @@ -150,10 +150,10 @@ Default slot bindings are no longer exposed to named slots and vice versa:

- count in default slot - is available: {count} + count in default slot — is available: {count}

- count in bar slot - is not available: {count} + count in bar slot — is not available: {count}

``` diff --git a/documentation/docs/07-misc/07-v5-migration-guide.md b/documentation/docs/07-misc/07-v5-migration-guide.md index 37da3b7b23..40cbc3bd9e 100644 --- a/documentation/docs/07-misc/07-v5-migration-guide.md +++ b/documentation/docs/07-misc/07-v5-migration-guide.md @@ -4,7 +4,7 @@ title: Svelte 5 migration guide Version 5 comes with an overhauled syntax and reactivity system. While it may look different at first, you'll soon notice many similarities. This guide goes over the changes in detail and shows you how to upgrade. Along with it, we also provide information on _why_ we did these changes. -You don't have to migrate to the new syntax right away - Svelte 5 still supports the old Svelte 4 syntax, and you can mix and match components using the new syntax with components using the old and vice versa. We expect many people to be able to upgrade with only a few lines of code changed initially. There's also a [migration script](#Migration-script) that helps you with many of these steps automatically. +You don't have to migrate to the new syntax right away — Svelte 5 still supports the old Svelte 4 syntax, and you can mix and match components using the new syntax with components using the old and vice versa. We expect many people to be able to upgrade with only a few lines of code changed initially. There's also a [migration script](#Migration-script) that helps you with many of these steps automatically. ## Reactivity syntax changes @@ -23,7 +23,7 @@ In Svelte 4, a `let` declaration at the top level of a component was implicitly Nothing else changes. `count` is still the number itself, and you read and write directly to it, without a wrapper like `.value` or `getCount()`. > [!DETAILS] Why we did this -> `let` being implicitly reactive at the top level worked great, but it meant that reactivity was constrained - a `let` declaration anywhere else was not reactive. This forced you to resort to using stores when refactoring code out of the top level of components for reuse. This meant you had to learn an entirely separate reactivity model, and the result often wasn't as nice to work with. Because reactivity is more explicit in Svelte 5, you can keep using the same API outside the top level of components. Head to [the tutorial](/tutorial) to learn more. +> `let` being implicitly reactive at the top level worked great, but it meant that reactivity was constrained — a `let` declaration anywhere else was not reactive. This forced you to resort to using stores when refactoring code out of the top level of components for reuse. This meant you had to learn an entirely separate reactivity model, and the result often wasn't as nice to work with. Because reactivity is more explicit in Svelte 5, you can keep using the same API outside the top level of components. Head to [the tutorial](/tutorial) to learn more. ### $: → $derived/$effect @@ -120,7 +120,7 @@ In Svelte 5, the `$props` rune makes this straightforward without any additional ## Event changes -Event handlers have been given a facelift in Svelte 5. Whereas in Svelte 4 we use the `on:` directive to attach an event listener to an element, in Svelte 5 they are properties like any other (in other words - remove the colon): +Event handlers have been given a facelift in Svelte 5. Whereas in Svelte 4 we use the `on:` directive to attach an event listener to an element, in Svelte 5 they are properties like any other (in other words — remove the colon): ```svelte +``` + ### hydration_failed ``` diff --git a/documentation/docs/98-reference/.generated/client-warnings.md b/documentation/docs/98-reference/.generated/client-warnings.md index c95ace2229..7daf808d61 100644 --- a/documentation/docs/98-reference/.generated/client-warnings.md +++ b/documentation/docs/98-reference/.generated/client-warnings.md @@ -140,6 +140,25 @@ The easiest way to log a value as it changes over time is to use the [`$inspect` %handler% should be a function. Did you mean to %suggestion%? ``` +### hydratable_missing_but_expected + +``` +Expected to find a hydratable with key `%key%` during hydration, but did not. +``` + +This can happen if you render a hydratable on the client that was not rendered on the server, and means that it was forced to fall back to running its function blockingly during hydration. This is bad for performance, as it blocks hydration until the asynchronous work completes. + +```svelte + +``` + ### hydration_attribute_changed ``` @@ -218,7 +237,7 @@ Hydration failed because the initial UI does not match what was rendered on the This warning is thrown when Svelte encounters an error while hydrating the HTML from the server. During hydration, Svelte walks the DOM, expecting a certain structure. If that structure is different (for example because the HTML was repaired by the DOM because of invalid HTML), then Svelte will run into issues, resulting in this warning. -During development, this error is often preceeded by a `console.error` detailing the offending HTML, which needs fixing. +During development, this error is often preceded by a `console.error` detailing the offending HTML, which needs fixing. ### invalid_raw_snippet_render diff --git a/documentation/docs/98-reference/.generated/compile-errors.md b/documentation/docs/98-reference/.generated/compile-errors.md index 5262e12fe7..2645a0c459 100644 --- a/documentation/docs/98-reference/.generated/compile-errors.md +++ b/documentation/docs/98-reference/.generated/compile-errors.md @@ -525,6 +525,12 @@ Expected an identifier Expected identifier or destructure pattern ``` +### expected_tag + +``` +Expected 'html', 'render', 'attach', 'const', or 'debug' +``` + ### expected_token ``` @@ -561,6 +567,12 @@ Cannot use `await` in deriveds and template expressions, or at the top level of `$host()` can only be used inside custom element component instances ``` +### illegal_await_expression + +``` +`use:`, `transition:` and `animate:` directives, attachments and bindings do not support await expressions +``` + ### illegal_element_attribute ``` diff --git a/documentation/docs/98-reference/.generated/server-errors.md b/documentation/docs/98-reference/.generated/server-errors.md index 6263032212..4d05e04207 100644 --- a/documentation/docs/98-reference/.generated/server-errors.md +++ b/documentation/docs/98-reference/.generated/server-errors.md @@ -1,5 +1,13 @@ +### async_local_storage_unavailable + +``` +The node API `AsyncLocalStorage` is not available, but is required to use async server rendering. +``` + +Some platforms require configuration flags to enable this API. Consult your platform's documentation. + ### await_invalid ``` @@ -14,6 +22,39 @@ You (or the framework you're using) called [`render(...)`](svelte-server#render) The `html` property of server render results has been deprecated. Use `body` instead. ``` +### hydratable_clobbering + +``` +Attempted to set `hydratable` with key `%key%` twice with different values. + +%stack% +``` + +This error occurs when using `hydratable` multiple times with the same key. To avoid this, you can: +- Ensure all invocations with the same key result in the same value +- Update the keys to make both instances unique + +```svelte + +``` + +### hydratable_serialization_failed + +``` +Failed to serialize `hydratable` data for key `%key%`. + +`hydratable` can serialize anything [`uneval` from `devalue`](https://npmjs.com/package/uneval) can, plus Promises. + +Cause: +%stack% +``` + ### lifecycle_function_unavailable ``` @@ -21,3 +62,11 @@ The `html` property of server render results has been deprecated. Use `body` ins ``` Certain methods such as `mount` cannot be invoked while running in a server context. Avoid calling them eagerly, i.e. not during render. + +### server_context_required + +``` +Could not resolve `render` context. +``` + +Certain functions such as `hydratable` cannot be invoked outside of a `render(...)` call, such as at the top level of a module. diff --git a/documentation/docs/98-reference/.generated/server-warnings.md b/documentation/docs/98-reference/.generated/server-warnings.md new file mode 100644 index 0000000000..c4a7fbefef --- /dev/null +++ b/documentation/docs/98-reference/.generated/server-warnings.md @@ -0,0 +1,34 @@ + + +### unresolved_hydratable + +``` +A `hydratable` value with key `%key%` was created, but at least part of it was not used during the render. + +The `hydratable` was initialized in: +%stack% +``` + +The most likely cause of this is creating a `hydratable` in the `script` block of your component and then `await`ing +the result inside a `svelte:boundary` with a `pending` snippet: + +```svelte + + + +

{(await user).name}

+ + {#snippet pending()} +
Loading...
+ {/snippet} +
+``` + +Consider inlining the `hydratable` call inside the boundary so that it's not called on the server. + +Note that this can also happen when a `hydratable` contains multiple promises and some but not all of them have been used. diff --git a/documentation/docs/98-reference/.generated/shared-errors.md b/documentation/docs/98-reference/.generated/shared-errors.md index 07e13dea45..136b3f4957 100644 --- a/documentation/docs/98-reference/.generated/shared-errors.md +++ b/documentation/docs/98-reference/.generated/shared-errors.md @@ -1,5 +1,11 @@ +### experimental_async_required + +``` +Cannot use `%name%(...)` unless the `experimental.async` compiler option is `true` +``` + ### invalid_default_snippet ``` diff --git a/documentation/docs/99-legacy/10-legacy-on.md b/documentation/docs/99-legacy/10-legacy-on.md index f2ee694cc1..ba084a228b 100644 --- a/documentation/docs/99-legacy/10-legacy-on.md +++ b/documentation/docs/99-legacy/10-legacy-on.md @@ -43,7 +43,7 @@ The following modifiers are available: - `preventDefault` — calls `event.preventDefault()` before running the handler - `stopPropagation` — calls `event.stopPropagation()`, preventing the event reaching the next element -- `stopImmediatePropagation` - calls `event.stopImmediatePropagation()`, preventing other listeners of the same event from being fired. +- `stopImmediatePropagation` — calls `event.stopImmediatePropagation()`, preventing other listeners of the same event from being fired. - `passive` — improves scrolling performance on touch/wheel events (Svelte will add it automatically where it's safe to do so) - `nonpassive` — explicitly set `passive: false` - `capture` — fires the handler during the _capture_ phase instead of the _bubbling_ phase diff --git a/package.json b/package.json index ad60494bf2..12e59a2665 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "bench:debug": "node --allow-natives-syntax --inspect-brk ./benchmarking/run.js" }, "devDependencies": { - "@changesets/cli": "^2.29.7", + "@changesets/cli": "^2.29.8", "@sveltejs/eslint-config": "^8.3.3", "@svitejs/changesets-changelog-github-compact": "^1.1.0", "@types/node": "^20.11.5", @@ -41,7 +41,7 @@ "prettier-plugin-svelte": "^3.4.0", "svelte": "workspace:^", "typescript": "^5.5.4", - "typescript-eslint": "^8.24.0", + "typescript-eslint": "^8.48.1", "v8-natives": "^1.2.5", "vitest": "^2.1.9" } diff --git a/packages/svelte/CHANGELOG.md b/packages/svelte/CHANGELOG.md index bcf17fe45e..b6ea395a9d 100644 --- a/packages/svelte/CHANGELOG.md +++ b/packages/svelte/CHANGELOG.md @@ -1,5 +1,209 @@ # svelte +## 5.45.8 + +### Patch Changes + +- fix: set AST `root.start` to `0` and `root.end` to `template.length` ([#17125](https://github.com/sveltejs/svelte/pull/17125)) + +- fix: prevent erroneous `state_referenced_locally` warnings on prop fallbacks ([#17329](https://github.com/sveltejs/svelte/pull/17329)) + +## 5.45.7 + +### Patch Changes + +- fix: Add `