Skip to content

beforeUpdate called twice with bound reference #6016

@larbear

Description

@larbear

Describe the bug
This is a duplicate of #3290 which was closed, though the issue still exists.

beforeUpdate is called twice when using bind:this.

Logs
No errors were shown in logs

To Reproduce
https://svelte.dev/repl/3381c9b40dc8441a8e4ebfa48fd8c178 (credit to beomy)

<script>
  import { beforeUpdate, afterUpdate } from 'svelte';
  let p;

  beforeUpdate(() => {
    console.log('beforeUpdate');
  })

  afterUpdate(() => {
    console.log('afterUpdate');
  })
</script>

<p bind:this={p}></p>

Open the console to view the behavior. It produces:

beforeUpdate
afterUpdate
beforeUpdate

Expected behavior
beforeUpdate should only be called once during a single update cycle.

beforeUpdate
afterUpdate

Severity
Severity is High, as the the cycle should always end with an afterUpdate and not a repeated beforeUpdate.

Other
#3308, was made to potentially fix this issue but appears that it was never merged. The reason given was that it was fixed in 3.18.2, but the issue still exists. https://svelte.dev/repl/3381c9b40dc8441a8e4ebfa48fd8c178?version=3.18.2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcompilerChanges relating to the compiler

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions