Skip to content

Conversation

mperrotti
Copy link
Contributor

@mperrotti mperrotti commented Sep 10, 2025

Relates to https://github.com/github/primer/issues/5424 and https://github.com/github/primer/issues/5425
Closes https://github.com/github/primer/issues/5714

Changelog

New

Changed

Removed

sx support was removed from Link

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; if selected, include a brief description as to why

Testing & Reviewing

Merge checklist

Copy link

changeset-bot bot commented Sep 10, 2025

🦋 Changeset detected

Latest commit: bb77600

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@primer/react Major
@primer/styled-react Major

Not sure what this means? Click here to learn what changesets are.

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

@github-actions github-actions bot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Sep 10, 2025
Copy link
Contributor

👋 Hi, this pull request contains changes to the source code that github/github depends on. If you are GitHub staff, we recommend testing these changes with github/github using the integration workflow. Thanks!

@mperrotti mperrotti marked this pull request as ready for review September 10, 2025 23:32
@mperrotti mperrotti requested a review from a team as a code owner September 10, 2025 23:32
Copy link
Contributor

@Copilot 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 removes the Box component usage and sx prop from multiple components as part of a major migration. The changes eliminate the legacy styled-components dependency and styled system support, transitioning components to use CSS modules and modern polymorphic patterns instead.

Key Changes:

  • Removes sx prop support from components like Announce, AriaStatus, Dialog, Heading, Link, NavList, PageLayout, and UnderlineNav
  • Replaces Box component wrapping with direct HTML element rendering or CSS modules
  • Implements modern polymorphic component patterns using fixedForwardRef and PolymorphicProps

Reviewed Changes

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

Show a summary per file
File Description
packages/styled-react/src/types/AriaRole.ts Adds AriaRole type definitions for backwards compatibility
packages/styled-react/src/sx.ts Creates sx utility function for styled-components compatibility layer
packages/styled-react/src/index.tsx Updates exports and creates wrapped components with sx support
packages/styled-react/src/components/ New component wrappers that restore sx prop functionality
packages/react/src/utils/modern-polymorphic.ts New utility for modern polymorphic component patterns
packages/react/src/*/index.ts Updates component exports and type definitions
packages/react/src//.tsx Component implementations migrated from Box+sx to direct elements+CSS modules
packages/react/src//.module.css New CSS module styles replacing sx-based styling
packages/react/src//.docs.json Documentation updates removing deprecated sx prop references
packages/react/src//.test.tsx Test updates removing sx-related test cases

Comment on lines 20 to 21
// @ts-expect-error - PrimerPageLayout is not recognized as a valid component type
return <Wrapper as={PrimerPageLayout} ref={ref} {...props} />
Copy link
Preview

Copilot AI Sep 10, 2025

Choose a reason for hiding this comment

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

The @ts-expect-error comment indicates a type system issue that should be properly resolved rather than suppressed. Consider creating proper type definitions for PrimerPageLayout or using a more specific typing approach to avoid the need for error suppression.

Copilot uses AI. Check for mistakes.

Comment on lines 48 to 58
export type UnderlineItemProps<As extends React.ElementType = 'a'> = {
as?: As
className?: string
iconsVisible?: boolean
loadingCounters?: boolean
counter?: number | string
icon?: FC<IconProps> | React.ReactElement
id?: string
ref?: React.Ref<unknown>
} & SxProp
children?: React.ReactNode
} & SxProp &
PolymorphicProps<As, 'a'>
Copy link
Preview

Copilot AI Sep 10, 2025

Choose a reason for hiding this comment

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

The type definition includes both SxProp and modern polymorphic props. Since this PR is removing sx support, the SxProp should be removed from this type definition to maintain consistency with the migration goals.

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Stop judging me, Copilot. That's a separate issue. We'll get to it...

Copy link
Contributor

github-actions bot commented Sep 10, 2025

size-limit report 📦

Path Size
packages/react/dist/browser.esm.js 89.49 KB (-0.22% 🔽)
packages/react/dist/browser.umd.js 89.38 KB (-0.57% 🔽)

@github-actions github-actions bot requested a deployment to storybook-preview-6825 September 10, 2025 23:36 Abandoned
@github-actions github-actions bot temporarily deployed to storybook-preview-6825 September 10, 2025 23:50 Inactive
@mperrotti
Copy link
Contributor Author

This PR will pass integration tests with the following changes to imports in github-ui:
https://github.com/github/github-ui/pull/3212

@github-actions github-actions bot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Sep 24, 2025
Copy link
Contributor

👋 Hi, there are new commits since the last successful integration test. We recommend running the integration workflow once more, unless you are sure the new changes do not affect github/github. Thanks!

@mperrotti mperrotti changed the title Remove Box usage and sx prop from Heading, Link, and misc areas Remove Box usage and sx prop from Link and misc other areas (stories, etc) Sep 24, 2025
@github-actions github-actions bot removed the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Sep 24, 2025
@github-actions github-actions bot temporarily deployed to storybook-preview-6825 September 24, 2025 17:59 Inactive
Copy link
Contributor

👋 Hi, there are new commits since the last successful integration test. We recommend running the integration workflow once more, unless you are sure the new changes do not affect github/github. Thanks!

@github-actions github-actions bot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Sep 24, 2025
@github-actions github-actions bot temporarily deployed to storybook-preview-6825 September 24, 2025 18:12 Inactive
@github-actions github-actions bot added integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm and removed integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm labels Sep 25, 2025
Copy link
Contributor

👋 Hi, there are new commits since the last successful integration test. We recommend running the integration workflow once more, unless you are sure the new changes do not affect github/github. Thanks!

@@ -0,0 +1,35 @@
// Mostly taken from https://github.com/total-typescript/react-typescript-tutorial/blob/main/src/08-advanced-patterns/72-as-prop-with-forward-ref.solution.tsx
Copy link
Member

Choose a reason for hiding this comment

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

can you elaborate on the need for this over the regular polymorphic we've been using?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Our current approach causes the following problems:

  • I don't think there's a good way to use ForwardRefComponent without casting (as ForwardRefComponent)
  • We can't access the prop types to automatically generate component API docs (project @adierkens is working on) when we cast with as ForwardRefComponent
  • The ForwardRefComponent type isn't portable, so I get an error when I try to import a component that uses ForwardRefComponent into styled-react
  • The DistributiveOmit (usually) handles type collisions better (for example: we specify an onClick, but the native HTML element type has a conflicting onClick)
  • I think the ForwardRefComponent approach is less type-safe, but I don't remember the specifics

@adierkens or somebody who is actually good at TypeScript can keep me correct on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All that said, I'm fine with going back to ForwardRefComponent for now 🙂

This just felt like a good opportunity to level-up our component types.

@francinelucca francinelucca added this pull request to the merge queue Sep 26, 2025
Merged via the queue into main with commit 4196e0e Sep 26, 2025
43 of 47 checks passed
@francinelucca francinelucca deleted the mp/rm-box-and-sx-from-components branch September 26, 2025 21:10
@primer primer bot mentioned this pull request Sep 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration-tests: passing Changes in this PR do NOT cause breaking changes in gh/gh integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants