-
Notifications
You must be signed in to change notification settings - Fork 928
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
[All] Ensure all document
handlers are attached to ownerDocument
#1721
Comments
We're facing some issues similar to this when rendering within an iframe. Our current problem is that the Shouldn't the Portal's default behaviour be to attach it to the nearest |
We are stuck because of this so I opened a PR. It includes some of the important components |
Is there any update on this issue ? |
any updates? |
Chiming in on this, we are having a similar issue. We are running react on our main document, but then portaling into an iframe some other react components, including some radix primitives. Everything works except the focus guard is being put onto the main document, not the iframe, and I'm assuming event listeners as well. This is a pretty major issue for us as it means we can't use radix at all for iframe portaled components, and that severely breaks our UI consistency. |
Has anyone found a patch to make this work (even it's just a workaround)? |
We've run into this as well in our project. A solution or workaround would be greatly appreciated. |
Hitting the same issue. Has anyone found a solution or a workaround? |
Here's the solution we went with: import * as DialogPrimitive from '@radix-ui/react-dialog'
import { useState } from 'react'
import { useSafeLayoutEffect } from '../../../hooks/use-safe-layout-effect'
type DialogPortalProps = {
children: React.ReactNode
}
/**
* This component wraps Radix's Portal implementation to handle SSR issues
* as well as portalling to the wrong body element when rendering in an iframe.
*/
export function DialogPortal(props: DialogPortalProps) {
const { children } = props
const [tempNode, setTempNode] = useState<HTMLElement | null>(null)
const [portalNode, setPortalNode] = useState<HTMLElement | null>(null)
useSafeLayoutEffect(() => {
if (!tempNode) return
const portalNode = tempNode.ownerDocument.body
setPortalNode(portalNode)
}, [tempNode])
return portalNode ? (
<DialogPrimitive.Portal container={portalNode}>
{children}
</DialogPrimitive.Portal>
) : (
<span
ref={(el) => {
if (el) setTempNode(el)
}}
/>
)
} Very long since I wrote the code so maybe it could be simplified a little. But hopefully it's helpful to someone! |
@hugotiger Yout solution just sets container, this can be done separately. But current issue is about document event handlers inside iframes. Still waiting for fix |
Feature request
Overview
Currently, wherever we attach document handlers, we do so at the global
document
level.Following up from #1677 where it was patched only for
DismissableLayer
we need to find a solution to do this throughout the entire library.Additional context
Here's another recent discussion which demonstrates similar issues with tooltips rendered in iframes: #1715
The text was updated successfully, but these errors were encountered: