Skip to content

Fix permission guard to forward ref#2053

Merged
alexandrudanpop merged 1 commit intomainfrom
fix/guard
Mar 4, 2026
Merged

Fix permission guard to forward ref#2053
alexandrudanpop merged 1 commit intomainfrom
fix/guard

Conversation

@alexandrudanpop
Copy link
Copy Markdown
Contributor

@alexandrudanpop alexandrudanpop commented Mar 4, 2026

Fixes OPS-3833

Copilot AI review requested due to automatic review settings March 4, 2026 10:22
@linear
Copy link
Copy Markdown

linear Bot commented Mar 4, 2026

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Mar 4, 2026

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

Updates PermissionGuard to support ref forwarding (for “asChild”/Radix-style composition) by switching it from a simple children passthrough to a forwardRef component built on Radix Slot.

Changes:

  • Added @radix-ui/react-slot and wrapped rendered output in <Slot> to forward refs.
  • Converted PermissionGuard to React.forwardRef and set displayName.

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

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +16 to +20
>(({ children, ...rest }, ref) => {
return (
<Slot ref={ref} {...rest}>
{children}
</Slot>
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

...rest here includes permission, tooltipClassName, and tooltipLocation from PermissionGuardProps, and spreading them onto Slot will forward them to the child (often down to a DOM element). That can produce React "unknown prop" warnings and potentially leak permission into the rendered markup. Suggestion: don’t spread the guard-only props onto Slot (explicitly pick/omit these props before spreading, or remove the spread entirely if no passthrough props are intended).

Copilot uses AI. Check for mistakes.
Comment on lines +17 to +21
return (
<Slot ref={ref} {...rest}>
{children}
</Slot>
);
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

@radix-ui/react-slot expects a single valid React element child (it clones/merges props & refs). With children typed as React.ReactNode, callers can legally pass strings/fragments/arrays, which will throw at runtime when Slot tries to operate on it. Suggestion: narrow children to React.ReactElement (or React.ReactElement | null) or add a runtime React.isValidElement guard that falls back to returning children unmodified when it isn’t a single element.

Copilot uses AI. Check for mistakes.
);
});

PermissionGuard.displayName = 'PermissionGuard';
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

The PR description still contains placeholders (e.g., Fixes #<issue_number>) and the testing checklist isn’t filled out. Please update the PR metadata so reviewers can trace the change to an issue and understand what was validated.

Copilot uses AI. Check for mistakes.
@alexandrudanpop alexandrudanpop merged commit 81d1642 into main Mar 4, 2026
25 checks passed
@alexandrudanpop alexandrudanpop deleted the fix/guard branch March 4, 2026 10:28
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.

4 participants