Skip to content

Commit a75acec

Browse files
mendelkMendel Kramer
authored and
Mendel Kramer
committed
Check if hiddenTextarea is in current body
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
1 parent 411cc93 commit a75acec

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/calculateNodeHeight.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default function calculateNodeHeight(
3333
forceHiddenStyles(hiddenTextarea);
3434
}
3535

36-
if (hiddenTextarea.parentNode === null) {
36+
if (!document.body.contains(hiddenTextarea)) {
3737
document.body.appendChild(hiddenTextarea);
3838
}
3939

0 commit comments

Comments
 (0)