Transitions in Svelte only apply to elements entering or exiting the DOM.
For example this would apply the fade when the div is initially added to the DOM:
<div in:fade>{message}</div>
How can we add a transition instead when message changes?
Since Svelte cannot have keys on single elements, the only solution I've found is to use a single element array to trigger a new element in the DOM whenever the array changes which doesn't seem ideal:
<script>
let messages = ['hello world'];
function updateMessages (message) {
messages = [message];
}
</script>
{#each messages as message (message)}
<div in:fade>{message}</div>
{/each}