-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Description
Describe the bug
Having a promise that is stored in a state rune and awaited in the template code seems to have a bug where it uses the previously resolved value of the promise to render the template. The issue appeared in our codebase in a place where we have a promise returning data that can have different shapes. When the promise variable is reassigned a new promise our application crashes due to the code trying to access a value which is no longer available due to the variable having a new promise as its state.
I would have expected the re-assigning the variable containing the promise would instantly render the loading state such that the code inside the {then}
block would not be hit until the new promise has resolved. The example is quite simplified in the REPL but it shows the general problem.
So to reproduce:
- Have a state rune with promise that can return different shapes of data
- await the promise in the template and access the resolved value
- Re-assign the state variable and see that the application crashes
Reproduction
Click the button and see that the app crashes due to accessing a value which no longer exists since the promise has been updated to a new promise which should render the loading state instead of the data.
Repro: https://svelte.dev/playground/0515270734184612838039274f00acde?version=5.38.6
Logs
See the log in the REPL when clicking the button
System Info
System:
OS: macOS 15.5
CPU: (10) arm64 Apple M2 Pro
Memory: 148.02 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.15.0 - ~/.nvm/versions/node/v22.15.0/bin/node
npm: 10.9.2 - ~/.nvm/versions/node/v22.15.0/bin/npm
pnpm: 10.14.0 - ~/Library/pnpm/pnpm
Browsers:
Brave Browser: 137.1.79.118
Chrome: 139.0.7258.155
Edge: 139.0.3405.125
Safari: 18.5
Severity
annoyance