Skip to content

Replace theme=useTheme() instances with default theme - #6897

Merged
siddharthkp merged 11 commits into
mainfrom
cleanup-usetheme-instances
Oct 6, 2025
Merged

Replace theme=useTheme() instances with default theme#6897
siddharthkp merged 11 commits into
mainfrom
cleanup-usetheme-instances

Conversation

@siddharthkp

@siddharthkpsiddharthkp commented Sep 23, 2025

Copy link
Copy Markdown
Member

These are the tokens that are swapped from custom theme to default theme:

theme.space.2theme.colors.success.fgtheme.colors.border.defaulttheme.colors.border.mutedtheme.animation.easeOutCubic

This means that if a custom theme is passed to ThemeProvider, which modifies any of these tokens, they will not be used. Instead the default primer theme will be used. This should mean no changes for github/github-ui, but might surprise external users that have changed any of the tokens above in their custom themes.

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 23, 2025

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b81af99

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

@siddharthkpsiddharthkp self-assigned this Sep 23, 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!

@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 25, 2025
@github-actions
github-actionsBottemporarily deployed to storybook-preview-6897 September 25, 2025 14:23 Inactive
@siddharthkpsiddharthkp added the skip changeset This change does not need a changelog label Sep 25, 2025
@github-actions
github-actionsBottemporarily deployed to storybook-preview-6897 October 6, 2025 12:00 Inactive
@siddharthkpsiddharthkp added major release breaking changes and removed skip changeset This change does not need a changelog labels Oct 6, 2025
@siddharthkp
siddharthkp marked this pull request as ready for review October 6, 2025 12:17
@siddharthkp
siddharthkp requested a review from a team as a code ownerOctober 6, 2025 12:17
@siddharthkp
siddharthkp requested review from Copilot, francinelucca and jonrohan and removed request for jonrohanOctober 6, 2025 12:17

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 useTheme hook usage and replaces it with direct theme imports as part of cleanup efforts. The primary purpose is to use default theme values instead of context-derived themes for specific tokens.

Key changes:

  • Replaced useTheme hook with direct theme imports or CSS custom properties
  • Updated 5 specific tokens to use default theme values instead of custom theme context
  • This is a breaking change that may affect external users with custom themes

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
FileDescription
packages/react/src/stories/useFocusZone.stories.tsxReplaced theme context usage with CSS custom property for accent color
packages/react/src/UnderlineNav/styles.tsConverted function-based divider styles to static object with CSS custom properties
packages/react/src/UnderlineNav/UnderlineNavContext.tsxRemoved theme from context interface
packages/react/src/UnderlineNav/UnderlineNav.tsxRemoved theme context usage and updated divider style reference
packages/react/src/SegmentedControl/SegmentedControl.tsxReplaced theme context with CSS custom property for border color
packages/react/src/Overlay/Overlay.tsxReplaced theme context with direct theme import for space and animation values
packages/react/src/LabelGroup/LabelGroup.tsxReplaced theme context with direct theme import for space value
packages/react/src/ConfirmationDialog/ConfirmationDialog.features.stories.tsxReplaced theme context with CSS custom property for success color
.changeset/replace-usetheme-with-theme.mdAdded changeset documenting the breaking change

const {theme} = useTheme()
const slideAnimationDistance = parseInt(get('space.2')(theme).replace('px', ''))
const slideAnimationEasing = get('animation.easeOutCubic')(theme)
const slideAnimationDistance = parseInt(theme.space[2], 10)

CopilotAIOct 6, 2025

Copy link

Choose a reason for hiding this comment

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

The parseInt function should specify a radix (base 10) to avoid potential parsing issues. While you've added the radix parameter, the original code was parsing a string with 'px' suffix, but theme.space[2] may not have the 'px' suffix that the original code was handling with .replace('px', '').

Suggested change
constslideAnimationDistance=parseInt(theme.space[2],10)
constslideAnimationDistance=parseInt(String(theme.space[2]).replace('px',''),10)

Copilot uses AI. Check for mistakes.

@siddharthkpsiddharthkpOct 6, 2025

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

This is fine because theme.space[2] is hardcoded to '8px'

parseInt('8px', 10) = 8

@siddharthkpsiddharthkp changed the title Cleanup usetheme instancesReplace theme=useTheme() instances with default themeOct 6, 2025
@primer-integration

Copy link
Copy Markdown

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

@github-actions
github-actionsBottemporarily deployed to storybook-preview-6897 October 6, 2025 12:31 Inactive
@github-actionsgithub-actionsBot added integration-tests: failing Changes in this PR cause breaking changes in gh/gh and removed integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm labels Oct 6, 2025

@francineluccafrancinelucca left a comment

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.

@primer-integration

Copy link
Copy Markdown

🟢 ci completed with status success.

@github-actionsgithub-actionsBot added integration-tests: passing Changes in this PR do NOT cause breaking changes in gh/gh and removed integration-tests: failing Changes in this PR cause breaking changes in gh/gh labels Oct 6, 2025
@siddharthkp
siddharthkp added this pull request to the merge queueOct 6, 2025
Merged via the queue into main with commit c1448ccOct 6, 2025
45 checks passed
@siddharthkp
siddharthkp deleted the cleanup-usetheme-instances branch October 6, 2025 17:57
@primerprimerBot mentioned this pull request Oct 6, 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/ghmajor releasebreaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@siddharthkp@francinelucca