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

why diffProp function gets most recent property value on "value" update? #40

Open
srghma opened this issue May 15, 2020 · 4 comments
Open

Comments

@srghma
Copy link

srghma commented May 15, 2020

here

_, "value"do
let elVal = Fn.runFn2 unsafeGetProperty "value" el
if Fn.runFn2 Util.refEq elVal val2
then pure v2
else do
EFn.runEffectFn3 setProperty prop2 val2 el
pure v2

well, I kind of understand why, but still want to know the explanation

the other question is should we update other propNames this way?

for example react calls value, checked, selected the Controlled attributes and handles them differently (diffHydratedProperties)

@natefaubion
Copy link
Collaborator

In many browsers, though it may not be the case anymore, setting the input value always resets the cursor position/selection. This avoids setting it if it has not changed so as not to reset the cursor when you are typing. It's a common bit of virtual DOM "lore".

https://github.com/elm/virtual-dom/blob/5a5bcf48720bc7d53461b3cd42a9f19f119c5503/src/Elm/Kernel/VirtualDom.js#L496
https://github.com/snabbdom/snabbdom/blob/ffc166cdb4beae1c800ce2132821baea1c547d6f/src/modules/props.ts#L27

@srghma
Copy link
Author

srghma commented May 15, 2020

snabbdom does this only for value, elm does this for value and checked

why elm does this for checked too?

@natefaubion
Copy link
Collaborator

I don't know the answer to that. I've never had issues with checked. You could maybe follow the blame for that code.

@srghma
Copy link
Author

srghma commented May 15, 2020

it comes from this https://github.com/elm/virtual-dom/issues/117 issue

notice the checked False in this example https://ellie-app.com/qzwpBK5xxMa1

I dont know if this happens in halogen too

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

No branches or pull requests

2 participants