Always re-render the textContent?
See original GitHub issueThere’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:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
I use Firefox. BTW, I test in chrome, it seem ok.