From a43519c1f6996b2ddb5e4767e1ba86f2d2140ce1 Mon Sep 17 00:00:00 2001 From: Mendel Kramer Date: Tue, 28 Jul 2020 01:09:40 -0400 Subject: [PATCH] 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 #247 --- src/calculateNodeHeight.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calculateNodeHeight.ts b/src/calculateNodeHeight.ts index 418d3f07..26ac511c 100644 --- a/src/calculateNodeHeight.ts +++ b/src/calculateNodeHeight.ts @@ -33,7 +33,7 @@ export default function calculateNodeHeight( forceHiddenStyles(hiddenTextarea); } - if (hiddenTextarea.parentNode === null) { + if (!document.body.contains(hiddenTextarea)) { document.body.appendChild(hiddenTextarea); }