-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Open
Description
Describe the bug
Consider this rather contrived example. When I enter some text and blur the element, the input text is duplicated, first as plain text and then as HTML, though the content variable contains the right contents.
<script lang="ts">
let content = $state("");
</script>
<div onblur={(e) => { content = e.currentTarget.innerText; }} contenteditable>
{@html content}
</div>The real use case I have is a simple markdown editor. content is a markdown string. The div contains {@html markdownToHTML(content)}, and on blur, I do content = HTMLToMarkdown(e.currentTarget.innerHTML).
I've found a workaround using key, but I think it seems strange that it should be necessary:
{#key content}
<div onblur={(e) => { content = e.currentTarget.innerText; }} contenteditable>
{@html content}
</div>
{/key}Reproduction
https://svelte.dev/playground/ea78f3db19fa4fd2bdae97a908d0ddbf?version=5.41.1
Logs
System Info
Same as latest Svelte playgroundSeverity
annoyance
Metadata
Metadata
Assignees
Labels
No labels