fix: disallow effect creation after await#18299
Conversation
|
|
await
|
I think we've discovered something majorly broken here, and maybe made it worse on main?
My original idea for making this playground was to show that removing |
|
I notice that these... {(await x).value}
{(await y).value}
{y.value}
{(await fn()).value}...aren't being transformed to use $.template_effect(
// ...
[
async () => (await x).value,
async () => (await y).value,
async () => (await fn()).value
],
// ...
);So when Other than that, I think the behaviour in this PR is an improvement on |
|
(This, incidentally, is also the source of the |
|
Think I just fixed it, but about to jump on a call so will add a test later |
|
Still broken, but differently — |
|
Haven't fully figured this out but I think it's at least partly because Since it's tangential to the main purpose of this PR, and since we're in a better state here than we were on |
dummdidumm
left a comment
There was a problem hiding this comment.
agreed - though I'm not sure if it's the "created inside effect" case, because in async mode that does trigger (we changed that)
We incorrectly restore effect context after an
$derived(await ...)if it occurs inside an async function, but only for those, no otherawaitexpressions. This is buggy and wrong. We only want to restore context inside an async derived expression (including template expressions)so thatawait a + b` works correctly.It's possible that this will be a breaking change (albeit not semver-violating, because
experimental) for some people if they are creating effects after anawait(other than at the top level of a component). This is regrettable, but it should never have worked in the first place.