Set value property before selectionEnd and selectionStart#157
Open
drathier wants to merge 1 commit intoelm:masterfrom
Open
Set value property before selectionEnd and selectionStart#157drathier wants to merge 1 commit intoelm:masterfrom
drathier wants to merge 1 commit intoelm:masterfrom
Conversation
Changing the `value` property of a `textarea` also implicitly changes its `selectionEnd` and `selectionStart` properties. Since virtual-dom isn't aware of this, the in-memory copy of the dom now differs from the real dom in these properties, leading to bugs. Adding the logic to handle this properly requires handling a lot of edge cases, so I couldn't find a nice way to implement it considering that these properties are uncommon and code size is important, hence this hotfix. This hotfix always considers the `selectionStart` and `selectionEnd` properties modified, like we already do with `value` and `checked`. Setting these properties to themselves (moving the cursor/selection to where it already is) is idempotent so this should be safe.
|
Is there an Ellie or other example we can try this out on? |
|
Its not clear what issue this PR actually solves. Is there an issue this can be linked to, or can you provide a little more explanation here? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changing the
valueproperty of atextareaalso implicitly changes (step 4) itsselectionEndandselectionStartproperties. Since virtual-dom isn't aware of this, the in-memory copy of the dom now differs from the real dom in these properties, leading to bugs.Adding the logic to handle this properly requires handling a lot of edge cases, so I couldn't find a nice way to implement it considering that these properties are uncommon and code size is important, hence this hotfix.
This hotfix always considers the
selectionStartandselectionEndproperties modified, like we already do withvalueandchecked. Setting these properties to themselves (moving the cursor/selection to where it already is) is idempotent so this should be safe.I've tested this patch by modifying the js output by the compiler.
I've looked through the html spec; there doesn't seem to be other properties being implicitly modified.