Check if hiddenTextarea is in current body#292
Open
mendelk wants to merge 1 commit intoAndarist:mainfrom
Open
Conversation
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
💥 No ChangesetLatest commit: a43519c Merging this PR will not cause any packages to be released. If these changes should not cause updates to packages in this repo, this is fine 🙂 If these changes should be published to npm, you need to add a changeset. Click here to learn what changesets are, and how to add one. Click here if you're a maintainer who wants to add a changeset to this PR |
|
I encountered this situation (using Turbolinks) and can confirm that this PR solves the problem in my case. |
leosullivan1
added a commit
to leosullivan1/react-textarea-autosize
that referenced
this pull request
Apr 29, 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. See here for more details Andarist#292
Author
|
@Andarist Is there anything I can do to help get this merged? I get that you've got lots of other things vying for your attention! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In situations where the
document.bodywas replaced, the check ifhiddenTextarea.parentNode === nullwould returnfalseeven if in fact the newdocument.bodyhad no currenthiddenTextarea, thus requiring a new one to be appended. The new logic checks if!document.body.contains(hiddenTextarea), which should account for the currentdocument.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 === nullto confirm that it's in fact still in the current DOM tree.Fixes #247