Skip to content

Commit

Permalink
Fix failed to removeChild on Node bug (#2164)
Browse files Browse the repository at this point in the history
* fix `failed to removeChild on Node` bug

Let's introduce a bit more defensive code to make sure that the code
doesn't crash when we don't pass a `Node` to `removeChild`

* update changelog
  • Loading branch information
RobinMalfait authored Jan 9, 2023
1 parent c687c2e commit 08c0837
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/@headlessui-react/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix false positive warning about using multiple `<Popover.Button>` components ([#2146](https://github.com/tailwindlabs/headlessui/pull/2146))
- Fix `Tab` key with non focusable elements in `Popover.Panel` ([#2147](https://github.com/tailwindlabs/headlessui/pull/2147))
- Fix false positive warning when using `<Popover.Button />` in React 17 ([#2163](https://github.com/tailwindlabs/headlessui/pull/2163))
- Fix `failed to removeChild on Node` bug ([#2164](https://github.com/tailwindlabs/headlessui/pull/2164))

## [1.7.7] - 2022-12-16

Expand Down
4 changes: 3 additions & 1 deletion packages/@headlessui-react/src/components/portal/portal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ let PortalRoot = forwardRefWithAs(function Portal<
if (!trulyUnmounted.current) return
if (!target || !element) return

target.removeChild(element)
if (element instanceof Node && target.contains(element)) {
target.removeChild(element)
}

if (target.childNodes.length <= 0) {
target.parentElement?.removeChild(target)
Expand Down

0 comments on commit 08c0837

Please sign in to comment.