react-textarea-autosize icon indicating copy to clipboard operation
react-textarea-autosize copied to clipboard

Resize Stops Working after Browser Back

Open yucho opened this issue 6 years ago • 5 comments

First off, I wanna say thanks for this awesome module! I'm thoroughly happy with it. Now, the issue I'm experiencing might be specific to my project because I'm using react-router and turbolinks. After navigating through pages via browser back/forward, resizing no longer works.

I did some debugging and found out the cause. Sometimes, the browser creates a new document.body, but hiddenTextarea keeps pointing at old body (and hence causing memory leak. Not sure where this behavior is from, BFCache might be the culprit here).

The quick fix I found is to change the following statement in calculateNodeHeight.js

  // Before change
  if (hiddenTextarea.parentNode === null) {
    document.body.appendChild(hiddenTextarea);
  }
  // After change
  if (!document.body.contains(hiddenTextarea)) { /.../ }

This way, you can always check for the latest body to see whether or not hiddenTextarea exists in the current body instance. There might be a better way, but this is a one-liner fix.

If you'd like, I can quickly make the change, add some tests, and submit a PR. Let me know what you think :)

yucho avatar Aug 09 '19 22:08 yucho

I'm in a similar boat to @yucho. Can this be merged in?

mendelk avatar Jul 27 '20 17:07 mendelk

Please prepare a PR for this and I will take a look at it then.

Andarist avatar Jul 27 '20 18:07 Andarist

Wow, didn't expect this resurrection. I'll work on it when I get a chance!

yucho avatar Jul 28 '20 05:07 yucho

Sorry for the spam. @yucho Beat you to it :)

mendelk avatar Jul 28 '20 06:07 mendelk

@Andarist Did you get a chance to look at #292 ?

mendelk avatar Aug 13 '20 15:08 mendelk