-
Notifications
You must be signed in to change notification settings - Fork 820
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
RSC compatibility #2923
RSC compatibility #2923
Conversation
74b220e
to
934278a
Compare
React.useEffect(() => { | ||
if (typeof window !== 'undefined') { | ||
(window as any)[Symbol.for('radix-ui')] = true; | ||
}, []); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note this change, this is to allow simple primitives to be server components (like AccessibleIcon
)
No context for how it's used in the original PR, but seems benign to do the assignment in render:
#853
container?: HTMLElement | null; | ||
container?: Element | null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corresponds to the type expected by React.createPortal
const { container = globalThis?.document?.body, ...portalProps } = props; | ||
const { container: containerProp, ...portalProps } = props; | ||
const [mounted, setMounted] = React.useState(false); | ||
useLayoutEffect(() => setMounted(true), []); | ||
const container = containerProp || (mounted && globalThis?.document?.body); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a container isn't provided, we must render twice to avoid hydration errors
96d0a99
to
1d07a66
Compare
1d07a66
to
edfe14d
Compare
useLayoutEffect(() => setMounted(true), []); | ||
const container = containerProp || (mounted && globalThis?.document?.body); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From an end-user point-of-view don't we introduce an extra frame as React will not render the content at first execution but after a second render cycle?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually users can still pass the container to globalThis?.document?.body
to drop that extra frame. Forget about my comment
for rsc compat radix-ui/primitives#2923
'use client'
in key places