Skip to content

Commit

Permalink
check for outerHTML being on the object
Browse files Browse the repository at this point in the history
Some tools, like AG Grid, polyfill `HTMLElement` to an empty object.
This means that the `typeof HTMLElement !== 'undefined'` check passed,
but the `v instanceof HTMLElement` translated to `v instanceof {}` which
is invalid...

This hopefully solves it.

Alternatively, we could use `return v?.outerHTML ?? v`, but not sure if
that's always safe to do.
  • Loading branch information
RobinMalfait committed Sep 26, 2024
1 parent 5ca68a9 commit 46eea04
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 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,12 @@ 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) => {
if (typeof v === 'object' && v !== null && 'outerHTML' in v) {
return v.outerHTML
}
return v
}),
]
)
useIsoMorphicEffect(() => {
Expand Down

0 comments on commit 46eea04

Please sign in to comment.