Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Tharit opened this issue Apr 8, 2021 · 2 comments
Closed

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

Tharit opened this issue Apr 8, 2021 · 2 comments

Comments

@Tharit
Copy link

Tharit commented Apr 8, 2021

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.

@jasonlyu123
Copy link
Member

I also think this is a bug. In this repl the error variable is overridden by the resolved result of the promise. It only happens inside the await then block after an update happens.

I think the problem is with this line

update_child_context = b`#child_ctx[${this.then.value_index}] = #child_ctx[${this.catch.value_index}] = ${info}.resolved;`;

The variable with the same name is overridden

@Conduitry
Copy link
Member

This should be fixed in 3.38.0 - https://svelte.dev/repl/95746deee9e34eb8b45a02a673e00136?version=3.38.0

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

No branches or pull requests

3 participants