Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resize Stops Working after Browser Back #247

Open
yucho opened this issue Aug 9, 2019 · 5 comments · May be fixed by #292
Open

Resize Stops Working after Browser Back #247

yucho opened this issue Aug 9, 2019 · 5 comments · May be fixed by #292

Comments

@yucho
Copy link

yucho commented Aug 9, 2019

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 :)

@mendelk
Copy link

mendelk commented Jul 27, 2020

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

@Andarist
Copy link
Owner

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

@yucho
Copy link
Author

yucho commented Jul 28, 2020

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

mendelk added a commit to mendelk/react-textarea-autosize that referenced this issue Jul 28, 2020
In situations where the `document.body` was replaced, the check if `hiddenTextarea.parentNode === null` would return `false` even if in fact the _new_ `document.body` had no current `hiddenTextarea`, thus requiring a new one to be appended. The new logic checks if `!document.body.contains(hiddenTextarea)`, which should account for the _current_ `document.body`.

An alternative solution would be to check if `hiddenTextarea.isConnected`, which is probably more performant. Unfortunately, this property is not present in IE.

Yet another solution which _might_ be more performant at the expense of being more verbose, is to recursively check if `hiddenTextarea.parentNode === null` to confirm that it's in fact still in the _current_ DOM tree.

Fixes Andarist#247
mendelk added a commit to mendelk/react-textarea-autosize that referenced this issue Jul 28, 2020
In situations where the `document.body` was replaced, the check if `hiddenTextarea.parentNode === null` would return `false` even if in fact the _new_ `document.body` had no current `hiddenTextarea`, thus requiring a new one to be appended. The new logic checks if `!document.body.contains(hiddenTextarea)`, which should account for the _current_ `document.body`.

An alternative solution would be to check if `hiddenTextarea.isConnected`, which is probably more performant. Unfortunately, this property is not present in IE.

Yet another solution which _might_ be more performant at the expense of being more verbose, is to recursively check if `hiddenTextarea.parentNode === null` to confirm that it's in fact still in the _current_ DOM tree.

Fixes Andarist#247
mendelk added a commit to mendelk/react-textarea-autosize that referenced this issue Jul 28, 2020
In situations where the `document.body` was replaced, the check if `hiddenTextarea.parentNode === null` would return `false` even if in fact the _new_ `document.body` had no current `hiddenTextarea`, thus requiring a new one to be appended. The new logic checks if `!document.body.contains(hiddenTextarea)`, which should account for the _current_ `document.body`.

An alternative solution would be to check if `hiddenTextarea.isConnected`, which is probably more performant. Unfortunately, this property is not present in IE.

Yet another solution which _might_ be more performant at the expense of being more verbose, is to recursively check if `hiddenTextarea.parentNode === null` to confirm that it's in fact still in the _current_ DOM tree.

Fixes Andarist#247
mendelk added a commit to mendelk/react-textarea-autosize that referenced this issue Jul 28, 2020
In situations where the `document.body` was replaced, the check if `hiddenTextarea.parentNode === null` would return `false` even if in fact the _new_ `document.body` had no current `hiddenTextarea`, thus requiring a new one to be appended. The new logic checks if `!document.body.contains(hiddenTextarea)`, which should account for the _current_ `document.body`.

An alternative solution would be to check if `hiddenTextarea.isConnected`, which is probably more performant. Unfortunately, this property is not present in IE.

Yet another solution which _might_ be more performant at the expense of being more verbose, is to recursively check if `hiddenTextarea.parentNode === null` to confirm that it's in fact still in the _current_ DOM tree.

Fixes Andarist#247
mendelk pushed a commit to mendelk/react-textarea-autosize that referenced this issue Jul 28, 2020
In situations where the `document.body` was replaced, the check if `hiddenTextarea.parentNode === null` would return `false` even if in fact the _new_ `document.body` had no current `hiddenTextarea`, thus requiring a new one to be appended. The new logic checks if `!document.body.contains(hiddenTextarea)`, which should account for the _current_ `document.body`.

An alternative solution would be to check if `hiddenTextarea.isConnected`, which is probably more performant. Unfortunately, this property is not present in IE.

Yet another solution which _might_ be more performant at the expense of being more verbose, is to recursively check if `hiddenTextarea.parentNode === null` to confirm that it's in fact still in the _current_ DOM tree.

Fixes Andarist#247
mendelk added a commit to mendelk/react-textarea-autosize that referenced this issue Jul 28, 2020
In situations where the `document.body` was replaced, the check if `hiddenTextarea.parentNode === null` would return `false` even if in fact the _new_ `document.body` had no current `hiddenTextarea`, thus requiring a new one to be appended. The new logic checks if `!document.body.contains(hiddenTextarea)`, which should account for the _current_ `document.body`.

An alternative solution would be to check if `hiddenTextarea.isConnected`, which is probably more performant. Unfortunately, this property is not present in IE.

Yet another solution which _might_ be more performant at the expense of being more verbose, is to recursively check if `hiddenTextarea.parentNode === null` to confirm that it's in fact still in the _current_ DOM tree.

Fixes Andarist#247
mendelk added a commit to mendelk/react-textarea-autosize that referenced this issue Jul 28, 2020
In situations where the `document.body` was replaced, the check if `hiddenTextarea.parentNode === null` would return `false` even if in fact the _new_ `document.body` had no current `hiddenTextarea`, thus requiring a new one to be appended. The new logic checks if `!document.body.contains(hiddenTextarea)`, which should account for the _current_ `document.body`.

An alternative solution would be to check if `hiddenTextarea.isConnected`, which is probably more performant. Unfortunately, this property is not present in IE.

Yet another solution which _might_ be more performant at the expense of being more verbose, is to recursively check if `hiddenTextarea.parentNode === null` to confirm that it's in fact still in the _current_ DOM tree.

Fixes Andarist#247
@mendelk mendelk linked a pull request Jul 28, 2020 that will close this issue
@mendelk
Copy link

mendelk commented Jul 28, 2020

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

@mendelk
Copy link

mendelk commented Aug 13, 2020

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

derrickreimer pushed a commit to svycal/react-textarea-autosize that referenced this issue Feb 28, 2021
In situations where the `document.body` was replaced, the check if `hiddenTextarea.parentNode === null` would return `false` even if in fact the _new_ `document.body` had no current `hiddenTextarea`, thus requiring a new one to be appended. The new logic checks if `!document.body.contains(hiddenTextarea)`, which should account for the _current_ `document.body`.

An alternative solution would be to check if `hiddenTextarea.isConnected`, which is probably more performant. Unfortunately, this property is not present in IE.

Yet another solution which _might_ be more performant at the expense of being more verbose, is to recursively check if `hiddenTextarea.parentNode === null` to confirm that it's in fact still in the _current_ DOM tree.

Fixes Andarist#247
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants