feat: add $effect.allowed
rune
sveltejs/kit#13986 has this code:
try {
$effect.pre(() => {
// ...
});
} catch {
// ...
}
This is necessary because it needs to use an effect to manage the query cache, and $effect.tracking()
is false
when initialising a component.
Maybe $effect.active()
?
The downside of course is that $effect.tracking()
is already a source of confusion, and having $effect.active()
which is very similar but subtly different will exacerbate that.
nice to have
This adds the $effect.allowed
rune, an advanced feature that indicates whether an effect or async derived can be created in the current context. Effects and async deriveds can only be created when a root effect is active, and previously, the only way to know this was to try creating an effect and checking if it threw an error.
Closes #16366.
feat:
, fix:
, chore:
, or docs:
.packages/svelte/src
, add a changeset (npx changeset
).pnpm test
and lint the project with pnpm lint
pnpm add https://pkg.pr.new/svelte@16458
Latest commit: 5aff44a
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
A bit of bikeshading: the name active_root_effect()
confuses me. Also, I like Rich's $effect.allowed()
name as more close to the rune's purpose.
Yeah, I couldn't really think of a concise name for active_root_effect
I'm fine with whatever name we choose for the rune (as long as it makes sense), so I'll change it in a bit