Skip to content

Move styled-react hooks out of component modules#7943

Open
joshblack wants to merge 1 commit into
joshblack/eslint-react-refresh/fix-hooksfrom
joshblack/eslint-react-refresh/fix-styled-hooks
Open

Move styled-react hooks out of component modules#7943
joshblack wants to merge 1 commit into
joshblack/eslint-react-refresh/fix-hooksfrom
joshblack/eslint-react-refresh/fix-styled-hooks

Conversation

@joshblack

@joshblack joshblack commented Jun 8, 2026

Copy link
Copy Markdown
Member

Closes #

No linked issue.

Splits styled-react theme hooks and context out of component modules while preserving deprecated public exports from the package entrypoint.

Changelog

New

  • Added styled-react ThemeContext.ts, useTheme.ts, and useFeatureFlaggedTheme.ts modules.

Changed

  • Updated styled-react BaseStyles, ThemeProvider, feature-flagged theming, and package entrypoint imports/exports to use the new hook modules.

Removed

  • Removed exported hook declarations from styled-react component implementation files.

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; internal refactor for a legacy package with existing deprecated exports preserved.

Testing & Reviewing

Review that styled-react still exports useTheme and useColorSchemeVar from its package entrypoint.

Merge checklist

@changeset-bot

changeset-bot Bot commented Jun 8, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 50bd636

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 github-actions Bot added staff Author is a staff member integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm labels Jun 8, 2026
@github-actions

github-actions Bot commented Jun 8, 2026

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.

@joshblack joshblack added skip changeset This change does not need a changelog integration-tests: skipped manually Changes in this PR do not require an integration test labels Jun 8, 2026
@joshblack joshblack marked this pull request as ready for review June 8, 2026 17:37
Copilot AI review requested due to automatic review settings June 8, 2026 17:37
@joshblack joshblack requested a review from a team as a code owner June 8, 2026 17:37
@joshblack joshblack requested a review from siddharthkp June 8, 2026 17:37

Copilot AI 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 refactors @primer/styled-react theming by moving the styled-react theme context and hooks (useTheme, useColorSchemeVar) out of component implementation modules into dedicated hook/context modules, while keeping the deprecated public exports available from the package entrypoint.

Changes:

  • Introduces new modules: ThemeContext.ts, useTheme.ts, and useFeatureFlaggedTheme.ts to centralize theme context + hook logic.
  • Updates ThemeProvider, BaseStyles, and the package entrypoint to import/export hooks from the new modules instead of defining them inline.
  • Removes hook/context declarations from component implementation files that previously owned them.
Show a summary per file
File Description
packages/styled-react/src/index.tsx Rewires deprecated public exports to source hooks from the new hook module while keeping existing entrypoint surface.
packages/styled-react/src/components/useTheme.ts Adds the styled-react useTheme and useColorSchemeVar implementations backed by the new ThemeContext.
packages/styled-react/src/components/useFeatureFlaggedTheme.ts Adds feature-flag-aware hook exports that switch between @primer/react and styled-react theme contexts.
packages/styled-react/src/components/ThemeProvider.tsx Moves inline ThemeContext + hook declarations out to new modules; updates imports accordingly.
packages/styled-react/src/components/ThemeContext.ts Adds a dedicated ThemeContext module shared by ThemeProvider and hooks.
packages/styled-react/src/components/FeatureFlaggedTheming.tsx Removes hook exports from this module now that hooks live in useFeatureFlaggedTheme.ts.

Copilot's findings

  • Files reviewed: 7/7 changed files
  • Comments generated: 3

Comment on lines +15 to +19
export function useColorSchemeVar(values: Partial<Record<string, string>>, fallback: string) {
const enabled = useFeatureFlag('primer_react_styled_react_use_primer_theme_providers')
const styledValue = styledUseColorSchemeVar(values, fallback)
const primerValue = primerUseColorSchemeVar(values, fallback)
return enabled ? primerValue : styledValue
Comment on lines +15 to +20
export function useColorSchemeVar(values: Partial<Record<string, string>>, fallback: string) {
const enabled = useFeatureFlag('primer_react_styled_react_use_primer_theme_providers')
const styledValue = styledUseColorSchemeVar(values, fallback)
const primerValue = primerUseColorSchemeVar(values, fallback)
return enabled ? primerValue : styledValue
}
Comment on lines +18 to +30
export {
/**
* @deprecated Theming in JavaScript is no longer supported. Prefer using
* `@primer/primitives` and CSS Modules instead.
*/
useColorSchemeVar,
useTheme,

/**
* @deprecated Theming in JavaScript is no longer supported. Prefer using
* `@primer/primitives` and CSS Modules instead.
*/
type ThemeProviderProps,
} from './components/FeatureFlaggedTheming'
useColorSchemeVar,
} from './components/useFeatureFlaggedTheme'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm integration-tests: skipped manually Changes in this PR do not require an integration test skip changeset This change does not need a changelog staff Author is a staff member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants