Andarist / Andarist/react-textarea-autosize

Resize Stops Working after Browser Back

オープン
#247 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
TypeScript
スター
2.4k
フォーク
247
PR マージ指標
30日以内にマージされた PR はありません

説明

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`](https://github.com/andreypopp/react-textarea-autosize/blob/efc9bc8e843825038fa1c3e7b8e221b6c673b463/src/calculateNodeHeight.js#L60)
```JavaScript
// 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 :)

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。