10.0.0-alpha.1 - Passing tagName as a (redundant) prop to an HTML node causes an error
See original GitHub issuePassing tagName
as a prop like:
export default function () {
return <button tagName='button' />
};
Will result in an error like:
E-v1.js:formatted:10882 Uncaught (in promise) TypeError: Cannot assign to read only property 'tagName' of object '#<HTMLButtonElement>'
at w (E-v1.js:formatted:10882)
at g (E-v1.js:formatted:10859)
at A (E-v1.js:formatted:10999)
at _ (E-v1.js:formatted:10953)
at _ (E-v1.js:formatted:10948)
at _ (E-v1.js:formatted:10948)
at d (E-v1.js:formatted:10816)
at A (E-v1.js:formatted:11001)
at _ (E-v1.js:formatted:10953)
at _ (E-v1.js:formatted:10948)
I noticed this because I have a (sloppy but allowed) pattern in a couple places where we have custom elements (not shown in example), and specify tagName like so:
class CustomElement extends Component {
render () {
const TagName = this.props.tagName;
return <TagName {...this.props} />;
}
}
render(<CustomElement tagName='button' class='the-class'>...</CustomElement>, parentEl);
To accommodate this, I need to explicitly remove tagName
from props before passing it down. This can be solved like const propsToPass = Object.assign({}, this.props); delete propsToPass.tagName
, but it’s not a convenient pattern. Still, I think it might still be okay to leave it as is, as long as it’s mentioned as a breaking change. Thoughts?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Unknown Prop Warning - React
The unknown-prop warning will fire if you attempt to render a DOM element with a prop that is not recognized by React as...
Read more >Next.js: Error: React.Children.only expected to receive a ...
So there are two child nodes (One is space and another is <a> tag) which is invalid and hence such error occurs.
Read more >Element.getElementsByTagName() - Web APIs | MDN
The Element.getElementsByTagName() method returns a live HTMLCollection of elements with the given tag name.
Read more >terser/terser: JavaScript parser, mangler and ... - GitHub
One technique is to pass a random number on every compile to simulate mangling changing with different inputs (e.g. as you update the...
Read more >Changelog — Python 3.11.1 documentation
gh-99298: Fix an issue that could potentially cause incorrect error handling ... tags found in configuration files when no tag was passed to...
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
That would be pretty expensive. If supporting a tagName prop/attribute is important, it can be added to the list of skipped keys here:
https://github.com/developit/preact/blob/ddab4781de763465a641a7022d3f686ba88197dc/src/diff/props.js#L82
This will set it as an attribute, which seems logical.
We could introduce a
delete tagName
before we stick everything to the native node but that decision is not up to me