-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating a contenteditable w/ on:input function is prepending, not replacing, if initial value is empty #5018
Comments
@noahlh You can use binding However, this does seem to be a bug to me. I'm looking into it. |
I'm getting positive results if we check for the Swapping the following export function set_data(text, data) {
data = '' + data;
if (text.data !== data) text.data = data;
} with the this export function set_data(text, data) {
data = '' + data;
if (text.wholeText !== data) text.data = data;
} https://github.com/sveltejs/svelte/blob/master/src/runtime/internal/dom.ts#L196 |
@skippednote Awesome!! Thanks for the quick ID & fix on this. I did originally use the 2-way binding (which indeed works perfectly), but unfortunately for my application I need to do manual binding, since |
This is fixed in 3.24.0 - https://svelte.dev/repl/04d08576e3db43d6a7f5c3fd7ae593a3?version=3.24.0 |
@Conduitry @skippednote Sorry to be difficult, but I think this might not quite be fixed -- check out the REPL link above, but start typing and hit "enter" in the field. Same issue reappears :( |
@noahlh The URL you had shared earlier uses an older version of Svelte Try this https://svelte.dev/repl/04d08576e3db43d6a7f5c3fd7ae593a3?version=3.24.0 |
@skippednote Sorry - i wasn't clear. I was indeed referring to the link that Conduitry shared (same as yours). The issue appears resolved IF you only type text. But try typing some text then hitting Enter (eg putting in a line break). |
Hey @noahlh I will definitely say no to the using I will open the PR soon for review |
Fixes: sveltejs#5018 Fixes: sveltejs#5931 Issue caused because of setting the updated value to the data property of moustache text node, use innerText if parent have contenteditable attribute
After digging a little bit, realised innerText will not even work in the first place, a wrong approach, mostly IMO there should be a warning from svelte to avoid this kind of regression and use binding only. |
If this has to do with two adjacent text nodes can we just make an action that constantly normalizes? Seems to work here: https://svelte.dev/repl/6a2b5691f4c04889b9a68b3f60be6ce3?version=3.23.2 |
- split logic up into "is this a contenteditable element" and depending on the outcome use either .wholeText or .data to check if an update is necessary - add to puppeteer because jsdom does not support contenteditable - one test is skipped it because it fails right now but helps test #5018 --------- Co-authored-by: suxin2017 <1107178482@qq.com> Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com> Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com>
Using contenteditable is a nasty beast, and there's not much Svelte can do to make this behave correctly in all situations. Back when this issue was created |
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:
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!
The text was updated successfully, but these errors were encountered: