Skip to content

Remove Box usage and sx prop from Link and misc other areas (stories, etc) - #6825

Merged
francinelucca merged 56 commits into
mainfrom
mp/rm-box-and-sx-from-components
Sep 26, 2025
Merged

Remove Box usage and sx prop from Link and misc other areas (stories, etc)#6825
francinelucca merged 56 commits into
mainfrom
mp/rm-box-and-sx-from-components

Conversation

@mperrotti

@mperrottimperrotti commented Sep 10, 2025

Copy link
Copy Markdown
Contributor

Relates to https://github.com/github/primer/issues/5424 and https://github.com/github/primer/issues/5425
Closeshttps://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

@changeset-bot

changeset-botBot commented Sep 10, 2025

Copy link
Copy Markdown

🦋 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
NameType
@primer/reactMajor
@primer/styled-reactMajor

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-actionsgithub-actionsBot 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
@github-actions

Copy link
Copy Markdown
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 ownerSeptember 10, 2025 23:32

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

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
FileDescription
packages/styled-react/src/types/AriaRole.tsAdds AriaRole type definitions for backwards compatibility
packages/styled-react/src/sx.tsCreates sx utility function for styled-components compatibility layer
packages/styled-react/src/index.tsxUpdates 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.tsNew utility for modern polymorphic component patterns
packages/react/src/*/index.tsUpdates component exports and type definitions
packages/react/src//.tsxComponent implementations migrated from Box+sx to direct elements+CSS modules
packages/react/src//.module.cssNew CSS module styles replacing sx-based styling
packages/react/src//.docs.jsonDocumentation updates removing deprecated sx prop references
packages/react/src//.test.tsxTest 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} />

CopilotAISep 10, 2025

Copy link

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'>

CopilotAISep 10, 2025

Copy link

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
Copy Markdown
ContributorAuthor

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...

Comment threadpackages/react/src/UnderlineNav/UnderlineNavItem.tsx Outdated
Comment threadpackages/react/src/NavList/NavList.tsx Outdated
Comment threadpackages/react/src/ActionList/Item.tsx Outdated
@github-actions

github-actionsBot commented Sep 10, 2025

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize
packages/react/dist/browser.esm.js89.49 KB (-0.22% 🔽)
packages/react/dist/browser.umd.js89.38 KB (-0.57% 🔽)

@github-actions
github-actionsBot requested a deployment to storybook-preview-6825 September 17, 2025 22:49 Abandoned
@primer-integration

Copy link
Copy Markdown

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

@primer-integration

Copy link
Copy Markdown

🟢 ci completed with status success.

@mperrotti

Copy link
Copy Markdown
ContributorAuthor

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

Copy link
Copy Markdown
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

Copy link
Copy Markdown
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!

Comment threadpackages/styled-react/src/__tests__/primer-react.browser.test.tsx Outdated
@github-actions

Copy link
Copy Markdown
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!

Comment threadpackages/styled-react/src/__tests__/primer-react.browser.test.tsx Outdated
@@ -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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

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.

@primerprimerBot mentioned this pull request Sep 26, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration-tests: passingChanges in this PR do NOT cause breaking changes in gh/ghintegration-tests: recommendedThis 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.

5 participants

@mperrotti@pksjce@joshblack@francinelucca