Skip to content

Revert "Replace useRefObjectAsForwardedRef with useMergedRefs internally" - #7737

Merged
siddharthkp merged 1 commit into
mainfrom
revert-7638-create-use-combined-refs
Apr 9, 2026
Merged

Revert "Replace useRefObjectAsForwardedRef with useMergedRefs internally"#7737
siddharthkp merged 1 commit into
mainfrom
revert-7638-create-use-combined-refs

Conversation

@liuliu-dev

Copy link
Copy Markdown
Contributor

Reverts #7638

@changeset-bot

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: c5f47ce

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Action required

👋 Hi, this pull request contains changes to the source code that github/github-ui depends on. If you are GitHub staff, test these changes with github/github-ui using the integration workflow. Check the integration testing docs for step-by-step instructions. Or, apply the integration-tests: skipped manually label to skip these checks.

To publish a canary release for integration testing, apply the Canary Release label to this PR.

@github-actionsgithub-actionsBot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Apr 8, 2026
@liuliu-dev
liuliu-dev marked this pull request as ready for review April 8, 2026 16:43
@liuliu-dev
liuliu-dev requested a review from a team as a code ownerApril 8, 2026 16:43

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Reverts #7638 by switching internal “combined refs” usage back from useMergedRefs to useRefObjectAsForwardedRef across multiple components in @primer/react.

Changes:

  • Replace useMergedRefs usage with useRefObjectAsForwardedRef and pass local ref objects directly to underlying elements.
  • Update useMergedRefs docs/tests variable naming (mergedRefcombinedRef).
  • Remove the changeset that described the (now-reverted) internal ref-handling update.
Show a summary per file
FileDescription
packages/react/src/TextInputWithTokens/TextInputWithTokens.tsxReverts forwarded-ref wiring back to useRefObjectAsForwardedRef + local ref.
packages/react/src/PageLayout/PageLayout.tsxReverts Pane/Sidebar forwarded-ref wiring back to useRefObjectAsForwardedRef.
packages/react/src/Overlay/Overlay.tsxReverts overlay ref wiring back to useRefObjectAsForwardedRef.
packages/react/src/Link/Link.tsxReverts ref wiring and introduces a ref cast to satisfy polymorphic typing.
packages/react/src/hooks/useMergedRefs.tsRenames variables in JSDoc examples (mergedRefcombinedRef).
packages/react/src/hooks/tests/useMergedRefs.test.tsxRenames test variable usage accordingly.
packages/react/src/Heading/Heading.tsxReverts forwarded-ref wiring back to useRefObjectAsForwardedRef.
packages/react/src/Dialog/Dialog.tsxReverts forwarded-ref wiring back to useRefObjectAsForwardedRef.
packages/react/src/deprecated/DialogV1/Dialog.tsxReverts forwarded-ref wiring back to useRefObjectAsForwardedRef.
packages/react/src/Button/ButtonBase.tsxReverts forwarded-ref wiring and changes ref assignment on polymorphic component.
packages/react/src/Autocomplete/AutocompleteOverlay.tsxReverts combined ref handling for overlay scroll container.
packages/react/src/Autocomplete/AutocompleteInput.tsxReverts forwarded-ref wiring back to useRefObjectAsForwardedRef.
packages/react/src/Autocomplete/Autocomplete.test.tsxRemoves an explicit focus call in a menu-open test.
packages/react/src/ActionList/Heading.tsxReverts forwarded-ref wiring back to useRefObjectAsForwardedRef.
packages/react/src/ActionBar/ActionBar.tsxReverts forwarded-ref wiring back to useRefObjectAsForwardedRef for icon button.
.changeset/combined-refs-hook.mdDeletes the changeset introduced by the reverted PR.

Copilot's findings

  • Files reviewed: 16/16 changed files
  • Comments generated: 4

Comment on lines 53 to +57
data-inline={inline}
data-hover-color={hoverColor}
{...restProps}
ref={mergedRef}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
ref={innerRef as any}

CopilotAIApr 8, 2026

Copy link

Choose a reason for hiding this comment

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

ref={innerRef as any} (and disabling the lint rule) bypasses type-safety for the polymorphic as prop and can mask cases where the rendered component doesn’t support refs. Prefer keeping the ref fully typed (e.g., by using useMergedRefs again, or by expressing the polymorphic ref type explicitly) so TS can enforce that ref is valid for As without resorting to any.

Copilot uses AI. Check for mistakes.
Comment on lines +90 to +91
// @ts-ignore temporary disable as we migrate to css modules, until we remove PolymorphicForwardRefComponent
ref={innerRef}

CopilotAIApr 8, 2026

Copy link

Choose a reason for hiding this comment

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

Avoid introducing @ts-ignore on the ref assignment here; it hides a real typing mismatch between the polymorphic as element and innerRef’s declared element type. Consider typing innerRef to match the union of supported elements (e.g., button/anchor) or switching back to useMergedRefs so forwardedRef can be attached without suppressing TypeScript errors.

Suggested change
// @ts-ignore temporary disable as we migrate to css modules, until we remove PolymorphicForwardRefComponent
ref={innerRef}
ref={
Component==='a'
? (innerRefasReact.Ref<HTMLAnchorElement>)
: (innerRefasReact.Ref<HTMLButtonElement>)
}

Copilot uses AI. Check for mistakes.
Comment on lines 150 to 155
const inputNode = getByLabelText(AUTOCOMPLETE_LABEL)

expect(inputNode.getAttribute('aria-expanded')).not.toBe('true')
inputNode.focus()
fireEvent.click(inputNode)
fireEvent.keyDown(inputNode, {key: 'ArrowDown'})

CopilotAIApr 8, 2026

Copy link

Choose a reason for hiding this comment

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

Removing inputNode.focus() means this test now relies on fireEvent.click(inputNode) to focus/open the menu, which can make it pass even if the intended “ArrowDown when focused opens menu” behavior regresses (click may open the menu by itself). To keep the assertion targeted, focus the input (or assert the menu remains closed after click) before the ArrowDown keyDown.

Copilot uses AI. Check for mistakes.
Comment on lines 195 to 198
const featureFlagMaxHeightClampToViewport = useFeatureFlag('primer_react_overlay_max_height_clamp_to_viewport')
const overlayRef = useRef<HTMLDivElement>(null)
const mergedRef = useMergedRefs(forwardedRef, overlayRef)
useRefObjectAsForwardedRef(forwardedRef, overlayRef)
const slideAnimationDistance = 8 // var(--base-size-8), hardcoded to do some math

CopilotAIApr 8, 2026

Copy link

Choose a reason for hiding this comment

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

Switching back to useRefObjectAsForwardedRef reintroduces its known behavior of invoking callback refs on every re-render (see useRefObjectAsForwardedRef tests’ TODO), which can cause unnecessary work/side effects and is especially risky with React 19 callback refs that return cleanup functions. Prefer useMergedRefs here so refs are only updated on mount/unmount/target changes and React 19 cleanup refs are handled correctly.

Copilot uses AI. Check for mistakes.
@github-actions
github-actionsBottemporarily deployed to storybook-preview-7737 April 8, 2026 16:50 Inactive
@liuliu-devliuliu-dev added Canary Release Apply this label when you want CI to create a canary release of the current PR integration-tests: skipped manually Changes in this PR do not require an integration test and removed integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm labels Apr 8, 2026
@siddharthkpsiddharthkp added Canary Release Apply this label when you want CI to create a canary release of the current PR and removed Canary Release Apply this label when you want CI to create a canary release of the current PR labels Apr 9, 2026
@primer-integration

Copy link
Copy Markdown

👋 Hi from github/github-ui! Your integration PR is ready: https://github.com/github/github-ui/pull/18179

@primer-integration

Copy link
Copy Markdown

Integration test results from github/github-ui:

Failed CI  Failed
Passed VRT  Passed
Passed Projects  Passed

CI check runs linting, type checking, and unit tests. Check the workflow logs for specific failures.

Need help? If you believe this failure is unrelated to your changes, please reach out to the Primer team for assistance.

@siddharthkp

Copy link
Copy Markdown
Member

github/ci is failing, but the failures are not related to this PR, they are failing on main because of feature flags that were removed. Adding integration-tests: skipped manually

@siddharthkp
siddharthkp enabled auto-merge April 9, 2026 10:11
@siddharthkpsiddharthkp added integration-tests: skipped manually Changes in this PR do not require an integration test and removed integration-tests: skipped manually Changes in this PR do not require an integration test labels Apr 9, 2026
@siddharthkp
siddharthkp disabled auto-merge April 9, 2026 10:13
@siddharthkp
siddharthkp enabled auto-merge April 9, 2026 10:13
@siddharthkp
siddharthkp disabled auto-merge April 9, 2026 10:13
@siddharthkp
siddharthkp merged commit 903e739 into mainApr 9, 2026
89 checks passed
@siddharthkp
siddharthkp deleted the revert-7638-create-use-combined-refs branch April 9, 2026 10:13
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Canary ReleaseApply this label when you want CI to create a canary release of the current PRintegration-tests: skipped manuallyChanges in this PR do not require an integration test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@liuliu-dev@siddharthkp