react-textarea-autosize: `NaN` is an invalid value for the `height` css style property

`NaN` is an invalid value for the `height` css style property

My textarea is invisible initially, and the first render gives that error.

I stepped through the code, and it’s a result of calculateNodeStyling returning NaN props. Perhaps fallback them to 0 to avoid this?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 33 (14 by maintainers)

Most upvoted comments

I’ve released a new version, please check it out and report back if you find any issues with it or if it didn’t fix your original issue.

Closing as “possibly fixed” but feel free to revive the thread if necessary.

@Andarist, @jeffijoe I’ve implemented a PoC here https://codesandbox.io/s/48yjjrxvz0

The issue appears when you use minRows and mount it on a DOM node not yet in the tree.

I’m only slightly worried that mounting the rendered subtree might not cause a re-render and therefore height won’t be recalculated, but gonna wait for an actual report about this before taking any actions against that.

I’ll prepare a new release with a guard for this in the weekend.

I’d also like to add I get this error while writing my tests. As someone mentioned above, I too am using styled components to style the textarea. Using border: none will throw this error. If anyone comes across this, a way to silence this error is to use border: 0.

I’m noticing a similar warning when writing my tests. However, I’ve figured out what causes this warning to reproduce. I’m using styled-components to style the textarea, and whenever I use the attribute border: none it’s causing me to see this warning, any ideas as to why? Removing border from the styles silents the warning.

Definitely no benefit, simply returning null when it isn’t open solves this issue.

There are however other usecases I can see, building a complete node before attaching it to the DOM can be more efficient than building it after it’s attached, using document fragments for example.