feat: support using, link top-level using declarations in components to lifecycle#16192
feat: support using, link top-level using declarations in components to lifecycle#16192Rich-Harris wants to merge 8 commits into
using, link top-level using declarations in components to lifecycle#16192Conversation
🦋 Changeset detectedLatest commit: 8f5a073 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
using, link top-level using declarations in components to lifecycleusing, link top-level using declarations in components to lifecycle
|
Fun idea from bsky — |
So that would be like a 1 time $derived value? |
|
Would be nice to have corresponding template syntax |
|
This probably closes #8973 |
Hm... How it could be useful? |
The usage is the same as the top-level declaration, only in the If a real example is needed, I would like to get rid of |
|
Could anyone clarify status of support Now in any configuration in svelte.config.js: preprocess: vitePreprocess()
// or
preprocess: vitePreprocess({ script: true })and level:
I get error: But there are at least 2 places that say that it should work:
These documentation are wrong? |
|
This isn't a merged feature, Svelte currently doesn't support parsing |
https://github.com/tc39/proposal-explicit-resource-management
Alternative to #16190, with the distinction that
usingdeclarations 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
usinggets compiled away for client code, but that doesn't apply to server code or non-top-levelusing.)Before submitting the PR, please make sure you do the following
feat:,fix:,chore:, ordocs:.packages/svelte/src, add a changeset (npx changeset).Tests and linting
pnpm testand lint the project withpnpm lint