Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when using instanceof HTMLElement in some environments #3494

Merged
merged 3 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/@headlessui-react/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Ensure `Element` is available before polyfilling to prevent crashes in non-browser environments ([#3493](https://github.com/tailwindlabs/headlessui/pull/3493))
- Fix crash when using `instanceof HTMLElement` in some environments ([#3494](https://github.com/tailwindlabs/headlessui/pull/3494))

## [2.1.8] - 2024-09-12

Expand Down
19 changes: 8 additions & 11 deletions packages/@headlessui-react/src/internal/floating.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,14 @@ export function useFloatingPanel(
let stablePlacement = useMemo(
() => placement,
[
JSON.stringify(
placement,
typeof HTMLElement !== 'undefined'
? (_, v) => {
if (v instanceof HTMLElement) {
return v.outerHTML
}
return v
}
: undefined
),
JSON.stringify(placement, (_, v) => {
// When we are trying to stringify a DOM element, we want to return the
// `outerHTML` of the element. In all other cases, we want to return the
// value as-is.
// It's not safe enough to check whether `v` is an instanceof
// `HTMLElement` because some tools (like AG Grid) polyfill it to be `{}`.
return v?.outerHTML ?? v
}),
]
)
useIsoMorphicEffect(() => {
Expand Down