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.

10.0.0-alpha.1 - Passing tagName as a (redundant) prop to an HTML node causes an error

See original GitHub issue

Passing 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
developitcommented, Mar 14, 2019

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.

0reactions
JoviDeCroockcommented, Mar 14, 2019

We could introduce a delete tagName before we stick everything to the native node but that decision is not up to me

Read more comments on GitHub >

github_iconTop 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 >

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