Skip to content

Updating a contenteditable w/ on:input function is prepending, not replacing, if initial value is empty #5018

Closed
@noahlh

Description

@noahlh

Describe the bug
Sorry for the mouthful of a title. Showing is often easier than telling:

https://svelte.dev/repl/04d08576e3db43d6a7f5c3fd7ae593a3?version=3.23.2

If the initial value is empty, typing into the contenteditable div causes the value to be prepended with the previous value after each keystroke (instead of replaced). Eg typing "Hello" nets a value of:

HelloHelloHellHelHeH

This does not happen if a) the initial value of the field is non-empty or b) after you complete that initial input, you select all the garbage text, delete it, and re-enter new text.

Expected behavior
The value of the element's innerText should reflect exactly what is typed.

Information about your Svelte project:

  • Chrome 81 & Safari 13.1.1
  • MacOS 10.15.5
  • Svelte 3.23.2

Severity
Annoying / semi-blocking (I can work around this in my project, but it does prevent me from initializing the div with an empty value, which I'd prefer)

Additional context
Checked with #support on Discord and was suggested that I file a bug. I searched and couldn't find any related issues. Apologies in advance if this is my mistake and not actually a bug!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions