$effects created after the first top-level await never execute
#16691
$effects created after the first top-level await never executeDevelopment PRs
Closes #16691
Before submitting the PR, please make sure you do the following
- It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
- Prefix your PR title with
feat:,fix:,chore:, ordocs:. - This message body should clearly illustrate what problems it solves.
- Ideally, include a test that fails without this PR but passes with it.
- If this PR changes code within
packages/svelte/src, add a changeset (npx changeset).
Tests and linting
- Run the tests with
pnpm testand lint the project withpnpm lint
Alternative to #16721, partial alternative to #16709. Closes #16691, closes #16627, closes #16582 and #16651 as well.
Before submitting the PR, please make sure you do the following
- It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
- Prefix your PR title with
feat:,fix:,chore:, ordocs:. - This message body should clearly illustrate what problems it solves.
- Ideally, include a test that fails without this PR but passes with it.
- If this PR changes code within
packages/svelte/src, add a changeset (npx changeset).
Tests and linting
- Run the tests with
pnpm testand lint the project withpnpm lint
Issue
Describe the bug
See #16682 (comment)
The issue here is that regular user effects (ones made specifically with $effect, not $effect.pre or render effects) are deferred until the component is mounted. However, since the code that indicates the component as being mounted, $.pop, runs synchronously (even in async components), the effects are never added to the array of deferred effects for their component (and might(?) be added to the parent component if it exists) if they're created after the first top-level await.
Reproduction
Logs
System Info
N/A
Severity
annoyance
Info
@Ocean-OS does this issue cover onMount, bind:this, attachments, and actions as well (existing issues that can be closed as well, if so: #16582, #16627, #16651)?
I know you mentioned in a previous issue that onMount is just an untracked effect, so I wasn't sure if the other broken features are also all effects affected by this bug.
Thanks for your work on this.
onMount is covered by this, I'm not sure about the other issues though.