Skip to content
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

Set value property before selectionEnd and selectionStart #157

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

drathier
Copy link

@drathier drathier commented Jun 18, 2019

Changing the value property of a textarea also implicitly changes (step 4) 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.

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.

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.
@rupertlssmith
Copy link

Is there an Ellie or other example we can try this out on?

@rupertlssmith
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants