Skip to content

fix: fix CLS due to popover attribute not SSR#202

Merged
luwes merged 2 commits intomainfrom
fix-render
Nov 18, 2025
Merged

fix: fix CLS due to popover attribute not SSR#202
luwes merged 2 commits intomainfrom
fix-render

Conversation

@luwes
Copy link
Copy Markdown
Collaborator

@luwes luwes commented Nov 18, 2025

This pull request refactors and improves the handling of popup positioning and anchoring in both the Popover and Tooltip components. The changes focus on consistently generating and using a unique popupId for each popup, simplifying how popup and trigger elements are linked, and allowing custom styles to be passed to popups. This results in more reliable positioning, easier customization, and cleaner code.

Popover & Tooltip popup/trigger linking and positioning:

  • Introduced a consistent popupId (using useId and a custom format) in both Popover and Tooltip contexts, and propagated it through context and props for reliable identification and anchoring. [1] [2]
  • Refactored popup and trigger logic to use the context-provided popupId instead of generating or passing it separately, and removed redundant useEffect logic for setting attributes/styles. [1] [2] [3] [4]
  • Updated trigger elements to set commandfor and anchorName styles based on the popupId, improving the linking between trigger and popup for positioning. [1] [2]
  • Updated popup elements to set popover="manual" and use the positionAnchor style property with the generated popupId, ensuring correct positioning and anchoring. [1] [2]

Customization and extensibility:

  • Added support for custom style props on both PopoverPopup and TooltipPopup, allowing consumers to pass additional styles to popups. [1] [2]

@luwes luwes requested a review from Copilot November 18, 2025 01:37
@luwes luwes self-assigned this Nov 18, 2025
@vercel
Copy link
Copy Markdown

vercel bot commented Nov 18, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
vjs-10-demo-html Ready Ready Preview Comment Nov 18, 2025 1:40am
vjs-10-demo-next Ready Ready Preview Comment Nov 18, 2025 1:40am
vjs-10-demo-react Ready Ready Preview Comment Nov 18, 2025 1:40am
vjs-10-website Ready Ready Preview Comment Nov 18, 2025 1:40am

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes cumulative layout shift (CLS) issues by moving popover attribute setup from client-side useEffect to SSR-compatible direct attribute/style application. The core change generates a stable popupId in the root component and uses it consistently across trigger and popup elements through context, eliminating the need for post-render DOM manipulation.

Key Changes:

  • Generated popupId once in root components using useId() and shared via context
  • Moved popover="manual", commandfor, and anchor styles from useEffect to direct JSX attributes
  • Added style prop support to popup components for customization

Reviewed Changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 5 comments.

File Description
packages/react/src/components/Popover.tsx Refactored to generate popupId in root, apply attributes directly in JSX, and support custom popup styles
packages/react/src/components/Tooltip.tsx Applied same refactoring pattern as Popover for consistent SSR-compatible attribute handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/react/src/components/Popover.tsx Outdated
commandfor: popupId ?? undefined,
style: {
...existingStyle,
...(popupId ? { anchorName: `--${popupId}` as any } : {}),
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CSS property should be anchor-name (kebab-case) instead of anchorName (camelCase). React's style prop uses camelCase for JavaScript, but CSS Anchor Positioning uses anchor-name as the property name. This should be '--anchor-name': --${popupId}`` or use DOM manipulation.

Copilot uses AI. Check for mistakes.
commandfor: popupId ?? undefined,
style: {
...existingStyle,
...(popupId ? { anchorName: `--${popupId}` as any } : {}),
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CSS property should be anchor-name (kebab-case) instead of anchorName (camelCase). React's style prop uses camelCase for JavaScript, but CSS Anchor Positioning uses anchor-name as the property name. This should be '--anchor-name': --${popupId}`` or use DOM manipulation.

Suggested change
...(popupId ? { anchorName: `--${popupId}` as any } : {}),
...(popupId ? { 'anchor-name': `--${popupId}` } : {}),

Copilot uses AI. Check for mistakes.
role="tooltip"
popover="manual"
style={{
...(popupId ? { positionAnchor: `--${popupId}` as any } : {}),
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CSS property should be position-anchor (kebab-case) instead of positionAnchor (camelCase). React's style prop uses camelCase for JavaScript, but CSS Anchor Positioning uses position-anchor as the property name. This should be 'position-anchor': --${popupId}`` or use DOM manipulation.

Copilot uses AI. Check for mistakes.
className={className}
popover="manual"
style={{
...(popupId ? { positionAnchor: `--${popupId}` as any } : {}),
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CSS property should be position-anchor (kebab-case) instead of positionAnchor (camelCase). React's style prop uses camelCase for JavaScript, but CSS Anchor Positioning uses position-anchor as the property name. This should be 'position-anchor': --${popupId}`` or use DOM manipulation.

Copilot uses AI. Check for mistakes.
@vercel vercel bot temporarily deployed to Preview – vjs-10-website November 18, 2025 01:38 Inactive
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@vercel vercel bot temporarily deployed to Preview – vjs-10-demo-html November 18, 2025 01:39 Inactive
@vercel vercel bot temporarily deployed to Preview – vjs-10-demo-react November 18, 2025 01:39 Inactive
@vercel vercel bot temporarily deployed to Preview – vjs-10-demo-next November 18, 2025 01:39 Inactive
@vercel vercel bot temporarily deployed to Preview – vjs-10-website November 18, 2025 01:40 Inactive
@luwes luwes merged commit 0952673 into main Nov 18, 2025
7 checks passed
@luwes luwes deleted the fix-render branch November 18, 2025 01:41
@github-actions github-actions bot mentioned this pull request Nov 18, 2025
@github-actions github-actions bot mentioned this pull request Feb 26, 2026
@github-actions github-actions bot mentioned this pull request Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants