Skip to content

await blocks unnecessarily unmount and remount their children when the promise changes #8459

Closed
@lovasoa

Description

@lovasoa

Describe the bug

When the promise of an {#await ... } block changes from a resolved Promise to another resolved Promise, svelte unnecessarily unmounts and then remounts all the contents of the "then" fragment of the await block.

Reproduction

https://svelte.dev/repl/b70b678cc4304ccdac16419e6a979168?version=3.58.0

<script>
  	import ShowValue from "./ShowValue.svelte"
	
	const promise_a = Promise.resolve('a')
	const promise_b = Promise.resolve('b')

	let current_promise = promise_a;
</script>

{#await current_promise then value}
	<ShowValue {value} />
{/await}

<button on:click={()=>{current_promise = promise_a}}>Show Promise A</button>
<button on:click={()=>{current_promise = promise_b}}>Show Promise B</button>

Here, I wouldn't expect ShowValue to be unmounted and remounted when the buttons are clicked.
In more complex cases, when ShowValue is expensive to mount (when it has to do many DOM operations, for instance), this becomes a performance problem.

Logs

No response

System Info

Tested in svelte 3.58.0

Severity

annoyance

Metadata

Metadata

Assignees

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