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.

Always re-render the textContent?

See original GitHub issue

There’s a test code, when change the select, the other element’s textContent always re-render.

import { h, render, Component } from "preact";
/** @jsx h*/

class TestCase extends Component {
    constructor(...args) {
        super(...args);
        this.handleChange = this.handleChange.bind(this);
        this.state = {
            selectedValue: "foo",
            options: [
                "foo", "bar",
            ],
        };
    }
    handleChange(evt) {
        this.setState({
            selectedValue: evt.target.value,
        });
    }
    render() {
        return (
            <div>
                <label>Label: </label>
                <select value={this.state.selectedValue}
                        onChange={this.handleChange}>
                {
                    this.state.options.map((val, idx) => (
                        <option value={val}>{val}</option>
                    ))
                }
                </select>
                <span>another text</span>
            </div>
        );
    }
}

render(<TestCase />, document.body);


const observer = new MutationObserver(function (muts) {
    for (const mut of muts) {
        switch (mut.type) {
            case "characterData":
                console.log(mut.oldValue, mut.target);
                break;
        }
    }
});
observer.observe(document.body, {
    childList: true,
    subtree: true,
    characterData: true,
    characterDataOldValue: true,
});

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
developitcommented, Oct 19, 2016

Indeed! Just noticed you were a Firefox user, looks like it’s only an issue there. Firefox doesn’t seem to skip strictly equal assignments to TextNode#nodeValue, so we’ll want to add a check around this line to fix the issue:

https://github.com/developit/preact/blob/master/src/vdom/diff.js#L57

if (dom.nodeValue != vnode) dom.nodeValue = vnode;
1reaction
zbinlincommented, Oct 19, 2016

I use Firefox. BTW, I test in chrome, it seem ok.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to re-render hyperHTML to the same element after ...
I will try to answer as best as I can, but I'll start saying that when asking for help, it'd be much easier/better...
Read more >
Is it possible and/or good practice to use textContent ... - GitHub
Like you noted though, the trick is in knowing when to update/re-render when the values change. In the DOM there are a number...
Read more >
React Re-render Optimization - Medium
React Re-render Optimization. Composer is a feature that Hootsuite supports allowing users to create and publish messages to social media.
Read more >
A Thoughtful Way To Use React's useRef() Hook
In a React component, useState and useReducer can cause your component to re-render each time there is a call to the update functions....
Read more >
HTML DOM Element textContent Property - W3Schools
The textContent property sets or returns the text content of the specified node, and all its descendants. Note. When you set the textContent...
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