Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Rich-Harris
Copy link
Member

Alternative to #16612 which I think is probably a bit simpler, and hopefully results in a greater performance boost.

Whereas #16612 works by flushing parts of the effect tree when an invalidation occurs, such that to-be-destroyed effects are destroyed before they can re-execute, this comes from the opposite end — we continue to abort flushing if a state change occurs in a user effect, but only if that state change results in an existing effect being marked (the cause of #16072).

Fixes #16548.

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:, or docs:.
  • 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 test and lint the project with pnpm lint

Copy link

changeset-bot bot commented Aug 14, 2025

🦋 Changeset detected

Latest commit: 87e5d00

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

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

Copy link
Contributor

Playground

pnpm add https://pkg.pr.new/svelte@16623

@Rich-Harris
Copy link
Member Author

In f89e355 I tried restricting things to block effects, on the basis that (I think?) the only way #16072 could reoccur is if a block containing a scheduled effect is destroyed. It causes one of the finicky ordering tests to fail, so I don't know if it's the right fix, but I'm curious as to whether it'll address #16548 (comment).

Of note: while it helps in the case that you're rendering this component many times...

<script>
  let inited = $state(false);

  $effect(() => {
    inited = true;
  });
</script>

<p>{inited}</p>

...you do still get an erroneous infinite loop error if the inited state is referenced in a block effect:

<script>
  let inited = $state(false);

  $effect(() => {
    inited = true;
  });
</script>

{#if inited}
  <p>{inited}</p>
{/if}

@dummdidumm
Copy link
Member

Pretty sure you can fix the test by doing the same as I did in my latest commit to #16612 which is collecting all user/render effects of dirty branches regardless of whether they are dirty or not.

@dummdidumm
Copy link
Member

closing in favor of #16631

@dummdidumm dummdidumm closed this Aug 17, 2025
@dummdidumm dummdidumm deleted the gh-16548 branch August 17, 2025 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Application using LayerChart hanging after updating Svelte to 5.36.0+ (logging UpdatedAtError in 3.36.5+)
2 participants