-
Notifications
You must be signed in to change notification settings - Fork 945
DO_NOT_MERGE feat: Add UNSAFE_PortalProvider documentation
#2896
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
Open
alexcarpenter
wants to merge
5
commits into
main
Choose a base branch
from
alexcarpenter/portal-provider
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
edb6a54
feat: Add `UNSAFE_PortalProvider` documentation
alexcarpenter db47df9
Update manifest.json
alexcarpenter f07f2c5
Update portal-provider.mdx
alexcarpenter 8e17bbb
move to utilities and add vue example
alexcarpenter acde283
Merge branch 'main' into alexcarpenter/portal-provider
alexcarpenter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| --- | ||
| title: '`<UNSAFE_PortalProvider>`' | ||
| description: The <UNSAFE_PortalProvider> component allows Clerk floating UI elements to render inside custom containers instead of document.body. | ||
| sdk: astro, expo, nextjs, react, react-router, tanstack-react-start | ||
| --- | ||
|
|
||
| The `<UNSAFE_PortalProvider>` component allows you to specify a custom container for Clerk floating UI elements (popovers, modals, tooltips, etc.) that use portals. Only Clerk components within the provider will be affected—components outside the provider will continue to use the default `document.body` for portals. | ||
alexcarpenter marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| This is particularly useful when using Clerk components inside external UI libraries like [Radix Dialog](https://www.radix-ui.com/primitives/docs/components/dialog) or [React Aria Components](https://react-spectrum.adobe.com/react-aria/components.html), where portaled elements need to render within the dialog's container to remain interactable. | ||
|
|
||
| > [!CAUTION] | ||
| > This component is marked as `UNSAFE` because it is an escape hatch that modifies the portal behavior of Clerk components. Not all portal locations will work correctly—some may cause issues with styling, accessibility, or other functionality. Typically, it is best to portal to the root of your application (e.g., the `body` element), outside of any possible overflow or stacking contexts. Use `<UNSAFE_PortalProvider>` only when necessary, such as when Clerk components are rendered inside external dialogs or popovers, or when you need to group all portalled elements into a single container at the root of your app. | ||
| ## Usage | ||
|
|
||
| ### With Radix Dialog | ||
|
|
||
| A common use case is rendering Clerk components inside a Radix Dialog. Without `<UNSAFE_PortalProvider>`, the `<UserButton>` popover would render outside the dialog and may not be interactable. | ||
|
|
||
| ```tsx {{ filename: 'app/components/UserDialog.tsx' }} | ||
| 'use client' | ||
|
|
||
| import { useRef } from 'react' | ||
| import * as Dialog from '@radix-ui/react-dialog' | ||
| import { UNSAFE_PortalProvider, UserButton } from '@clerk/nextjs' | ||
|
|
||
| export function UserDialog() { | ||
| const containerRef = useRef<HTMLDivElement>(null) | ||
|
|
||
| return ( | ||
| <Dialog.Root> | ||
| <Dialog.Trigger>Open Dialog</Dialog.Trigger> | ||
| <Dialog.Portal> | ||
| <Dialog.Overlay /> | ||
| <Dialog.Content ref={containerRef}> | ||
| <UNSAFE_PortalProvider getContainer={() => containerRef.current}> | ||
| <UserButton /> | ||
| </UNSAFE_PortalProvider> | ||
| </Dialog.Content> | ||
| </Dialog.Portal> | ||
| </Dialog.Root> | ||
| ) | ||
| } | ||
| ``` | ||
|
|
||
| ## Properties | ||
|
|
||
| <Properties> | ||
| - `getContainer` | ||
| - `() => HTMLElement | null` | ||
|
|
||
| A function that returns the container element where portals should be rendered. This function is called each time a portal needs to be rendered, so it should return a stable reference to the container element. | ||
|
|
||
| --- | ||
|
|
||
| - `children` | ||
| - `React.ReactNode` | ||
|
|
||
| The Clerk components that should have their portals rendered into the custom container. | ||
| </Properties> | ||
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.
Uh oh!
There was an error while loading. Please reload this page.