Skip to content

Scope issue in #await :catch causes exceptions or wrong behaviour #6173

@Tharit

Description

@Tharit

Describe the bug
It seems that when an element within the :then block of an #await statement is updated after the first rendering, the error variable from the :catch block somehow "leaks" and overwrites other variables or causes an exception.

E.g. if you use {:catch error}, and the {:then} block also uses a variable named "error" things start to get weird.
In my actual application I have a "global" component variable named "error" that suddenly seems to hold the value of the awaited promise in some cases; and in other cases an exception is thrown within svelte.

To Reproduce
An exception will be triggered when clicking the button in this REPL; make sure to open e.g. Chrome Dev Tools before clicking the button.
The issue started in 3.25 - it worked fine with 3.24.1
https://svelte.dev/repl/95746deee9e34eb8b45a02a673e00136?version=3.37.0

Expected behavior
The naming of the error variable for the {:catch} block should not affect the :then block in any way; it should be scoped correctly.

Severity
Blocks update / would require renaming of variables in many component.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions