feat: support using
, link top-level using
declarations in components to lifecycle
Alternative to #16190, with the distinction that using
declarations at the top level of a component are only disposed when the component unmounts.
I think I prefer this — it's more useful and more intuitive. Demo here.
On the server it doesn't transform anything, meaning resources are correctly disposed of once rendering is complete. Obviously all this is of limited use until support is sufficiently widespread, but I don't see any reason to hold it back until then. (The demo above actually works in all browsers, because top-level using
gets compiled away for client code, but that doesn't apply to server code or non-top-level using
.)
feat:
, fix:
, chore:
, or docs:
.packages/svelte/src
, add a changeset (npx changeset
).pnpm test
and lint the project with pnpm lint
Latest commit: 8f5a073
The changes in this PR will be included in the next version bump.
Name | Type |
---|---|
svelte | Minor |
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
pnpm add https://pkg.pr.new/svelte@16192
Fun idea from bsky — using x = $derived(...)
. Like regular using
this would also be disposed on component unmount, but would additionally be disposed when the derived updated. Not quite sure what would happen outside the top level of a component though... maybe it would be forbidden to use it with unowned deriveds
Fun idea from bsky —
using x = $derived(...)
. Like regularusing
this would also be disposed on component unmount, but would additionally be disposed when the derived updated. Not quite sure what would happen outside the top level of a component though... maybe it would be forbidden to use it with unowned deriveds
So that would be like a 1 time $derived value?