question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compare user-changeable element properties against their actual values from the element

See original GitHub issue

In props.js when updating the properties, we compare the new props against the oldProps of that vnode, instead of comparing against the actual properties of that element.

This causes problems when updating user-changeable properties of an element (like value or checked property of an input or textarea). Just typing into an input field already changes the property value of value, the assumptions that only snabbdom changes the property is not true.

For example, we want to clear the value an input field, whenever a button is clicked. We can then patch the node with { "props": { "value": "" }}. But what if the user changes the value of the input field in between. Then comparing only the old properties and new properties of the vnode does not suffice.

An example to illustrate the behavior: https://jsfiddle.net/0q6uueou/4/#.

How about changing the relevant code in props.js to this?

    for (key in props) {
        cur = props[key];
        old = elm[key];

        if (old !== cur) {
            elm[key] = cur;
        }
    }

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:2
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
cornermancommented, Nov 29, 2017

I just measured and reading from dom seems to be ~10x slower than from virtual dom. But both are still quite fast enough to not matter in most cases (~50M ops/sec).

https://jsperf.com/property-plain/1

0reactions
mightyiamcommented, Jan 17, 2020

A PR to solve this could possibly benefit from a benchmark system.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem with updating user-changeable properties · Issue #105 ...
For me, the intuitive behavior would be to compare against the real element properties instead of the old snabbdom props, i.e. fix it...
Read more >
The difference between attributes and properties in vanilla JS
In JavaScript (the DOM, really), an element has attributes and properties. ... However, user-changeable form properties—noteably, value ...
Read more >
Compare Elements | Periodic Table Element Comparison
1 2 13 14 1 1. H. Hydrogen. 1.008 2 3. Li. Lithium. 6.941 4. Be. Beryllium. 9.012 5. B. Boron. 10.811 6. C. Car... 3...
Read more >
Compare Element Attribute Value - YouTube
We can check that both elements either have the same attribute or do not have it.cy.get('#member') ... Your browser can't play this video....
Read more >
Default Policy for Managed Objects - ForgeRock Backstage
A managed object policy configuration element, defined in your project's conf/managed.json ... value is the value of the property that is being validated....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found