svelte icon indicating copy to clipboard operation
svelte copied to clipboard

Svelte 5: #await block is evaluated after component is no longer rendered

Open jamesst20 opened this issue 1 year ago • 1 comments

Describe the bug

I have this code. As you can see on line 38 and 46, I have an await block that calls a promise to check if the current authenticated user is allowed to do some kind of action and display the button if so.

Screenshot 2024-09-13 at 11 27 02 AM

It basically render this.

Screenshot 2024-09-13 at 11 11 41 AM

Thing is when I change page, I get this error:

Screenshot 2024-09-13 at 11 27 22 AM

I must change line 47 to {#if policyResult && project?.id} to get rid of it. In my project it doesn't seems to matter if the promise has already resolved or not, it will still trigger the error. My bet would be that the page change must be re-triggering the pomise right before leaving the page likely because the project props changes to undefined. However! the key difference here is that it doesn't crash on line 29 but it does on line 48 which means it is evaluated sometimes later.

Reproduction

Honestly the project is too big to just share it and I wasn't sure what was the simplest aproach.

I made something where you can trigger the same error if you switch page before the promises are resolved:

REPL

I hope this is enough and it does replicate the "same" bug

System Info

5.0.0-next.245

Severity

annoyance

jamesst20 avatar Sep 13 '24 15:09 jamesst20

I successfully reproduced the bug with this REPL.

I think I found the origin of the problem, I will try to make a PR...

adiguba avatar Sep 13 '24 19:09 adiguba

Closed by #13241

dummdidumm avatar Sep 15 '24 05:09 dummdidumm