Skip to content

Remove legacy JS theming (colorSchemes) from @primer/react#8212

Open
mattcosta7 wants to merge 7 commits into
mainfrom
theming/remove-legacy-js-theme
Open

Remove legacy JS theming (colorSchemes) from @primer/react#8212
mattcosta7 wants to merge 7 commits into
mainfrom
theming/remove-legacy-js-theme

Conversation

@mattcosta7

@mattcosta7 mattcosta7 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Closes #

theme.colorSchemes is enormous (~20KB gzip of the bundle) and was only truly needed by the legacy styled-react theming path. This PR removes the legacy JS theming from @primer/react and vendors what remains into @primer/styled-react. Colors are already applied via CSS variables (data-color-mode/data-light-theme/data-dark-theme), so there is no visual change.

Changelog

Changed

  • @primer/react's default theme no longer contains colorSchemes; ThemeProvider no longer merges color-scheme values into the theme context.
  • colorSchemes and the legacy-theme data now live in @primer/styled-react, which keeps its existing styled theming behavior.

Removed

  • theme.colorSchemes from @primer/react.
  • useTheme() no longer returns theme or resolvedColorScheme (it still returns colorScheme, colorMode, resolvedColorMode, dayScheme, nightScheme, and the setters).
  • Passing an unknown color scheme no longer logs an error.
  • The ThemeColorPaths and ThemeShadowPaths types are no longer exported from @primer/react (moved into @primer/styled-react).

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan

If approved, this would be merged when the next breaking is scheduled, and not before. github-ui should already be in a place to consume this, and the old behavior still exists via styled-react where it was necessary

  • None; if selected, include a brief description as to why

Consumers should apply color schemes via CSS (the data-* attributes rendered by ThemeProvider) rather than reading colors off useTheme().theme. Consumers who need the legacy JS colorSchemes object should migrate to @primer/styled-react.

Testing & Reviewing

  • @primer/react: type-check clean, ThemeProvider unit tests pass, exports snapshot updated.
  • @primer/styled-react: type-check clean, browser suite passes; the vendored colorSchemes precompile step reproduces identical output.

No visual regressions are expected since color application is CSS-driven.

Relocate colorSchemes and legacy-theme into @primer/styled-react, thin down ThemeProvider, and drop vestigial theme/resolvedColorScheme from useTheme().
@changeset-bot

changeset-bot Bot commented Jul 21, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f3ed4f0

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

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

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

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.

@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 Jul 21, 2026
@primer

primer Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

🤖 Lint and formatting issues have been automatically fixed and committed to this PR.

@github-actions
github-actions Bot temporarily deployed to storybook-preview-8212 July 21, 2026 23:03 Inactive
@primer

primer Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

🤖 Lint issues have been automatically fixed and committed to this PR.

…urn type

- Add script/**/*.ts to styled-react tsconfig so the moved precompile script resolves in the TS project (fixes eslint parse error).\n- Point .prettierignore at the relocated color-schemes.ts (prevents prettier from unquoting keys, which tripped camelcase).\n- Type the feature-flagged useTheme() with styled-react's own richer context so resolvedColorScheme/theme remain on styled-react's public API.
The generated file is now in .prettierignore; keep its quoted keys so the camelcase rule stays satisfied.
@github-actions
github-actions Bot temporarily deployed to storybook-preview-8212 July 21, 2026 23:33 Inactive
@mattcosta7 mattcosta7 self-assigned this Jul 22, 2026
@mattcosta7 mattcosta7 added the Canary Release Apply this label when you want CI to create a canary release of the current PR label Jul 22, 2026
@github-actions
github-actions Bot temporarily deployed to storybook-preview-8212 July 22, 2026 00:20 Inactive
@mattcosta7
mattcosta7 marked this pull request as ready for review July 22, 2026 11:25
@mattcosta7
mattcosta7 requested a review from a team as a code owner July 22, 2026 11:25
@mattcosta7
mattcosta7 requested review from TylerJDev and Copilot July 22, 2026 11:25

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 removes the legacy JS theme.colorSchemes payload from @primer/react and shifts the remaining legacy “JS theme” surface area into @primer/styled-react, while keeping color application CSS-driven via data-* attributes and CSS variables.

Changes:

  • @primer/react: stop merging colorSchemes into ThemeProvider context; remove theme/resolvedColorScheme from useTheme() and drop related exported path types.
  • @primer/styled-react: introduce a new default theme that re-attaches legacy colorSchemes, update themeGet/sx typing imports, and vendor legacy theme data.
  • Add a precompile step in @primer/styled-react to generate legacy-theme/ts/color-schemes.ts during build, plus changesets and packaging updates.
Show a summary per file
File Description
packages/styled-react/tsconfig.json Include build-time scripts in TS project.
packages/styled-react/src/theme.ts New styled-react default theme extending @primer/react base theme with colorSchemes.
packages/styled-react/src/theme-types.ts New local ThemeColorPaths/ThemeShadowPaths types for styled-react.
packages/styled-react/src/theme-get.ts Point themeGet at styled-react’s theme (with legacy colorSchemes).
packages/styled-react/src/sx.ts Import Theme*Paths types from styled-react instead of @primer/react.
packages/styled-react/src/legacy-theme/ts/index.ts New legacy-theme entry export(s).
packages/styled-react/src/legacy-theme/ts/color-schemes.ts Generated vendored colorSchemes output for styled-react.
packages/styled-react/src/legacy-theme/ts/colors/index.ts New scheme map aggregating per-scheme variables.
packages/styled-react/src/legacy-theme/ts/colors/light.ts Vendored light scheme variables.
packages/styled-react/src/legacy-theme/ts/colors/light_high_contrast.ts Vendored light high-contrast scheme variables.
packages/styled-react/src/legacy-theme/ts/colors/light_colorblind.ts Vendored light colorblind scheme variables.
packages/styled-react/src/legacy-theme/ts/colors/light_tritanopia.ts Vendored light tritanopia scheme variables.
packages/styled-react/src/legacy-theme/ts/colors/dark.ts Vendored dark scheme variables.
packages/styled-react/src/legacy-theme/ts/colors/dark_dimmed.ts Vendored dark dimmed scheme variables.
packages/styled-react/src/legacy-theme/ts/colors/dark_high_contrast.ts Vendored dark high-contrast scheme variables.
packages/styled-react/src/legacy-theme/ts/colors/dark_colorblind.ts Vendored dark colorblind scheme variables.
packages/styled-react/src/legacy-theme/ts/colors/dark_tritanopia.ts Vendored dark tritanopia scheme variables.
packages/styled-react/src/legacy-theme/README.md Documents the vendored legacy theme intent/source.
packages/styled-react/src/index.tsx Re-export theme from styled-react (instead of @primer/react).
packages/styled-react/src/components/useFeatureFlaggedTheme.ts Align feature-flagged useTheme typing with styled-react path.
packages/styled-react/src/components/ThemeProvider.tsx Use styled-react theme as default (restoring colorSchemes behavior).
packages/styled-react/script/precompile-color-schemes.ts New generator script for colorSchemes in styled-react.
packages/styled-react/script/build Run precompile step before bundling.
packages/styled-react/package.json Add precompile script + tsx devDep; adjust published files excludes.
packages/react/src/utils/useTheme.hookDocs.json Remove theme and resolvedColorScheme from generated hook docs.
packages/react/src/ThemeProvider.tsx Remove JS scheme merging; keep CSS data-*-driven theming only.
packages/react/src/ThemeContext.ts Remove theme and resolvedColorScheme from context typing.
packages/react/src/theme.ts Remove colorSchemes field and Theme*Paths exports from default theme module.
packages/react/src/index.ts Stop exporting ThemeColorPaths/ThemeShadowPaths from @primer/react.
packages/react/src/tests/ThemeProvider.test.tsx Remove tests for resolvedColorScheme behavior.
packages/react/src/tests/snapshots/exports.test.ts.snap Update export snapshot to reflect removed types.
packages/react/script/precompile-color-schemes.ts Remove generator script from @primer/react.
packages/react/script/build Stop running colorSchemes precompile as part of react build.
packages/react/package.json Remove deepmerge + precompile script + legacy-theme packaging exclude.
package-lock.json Move tsx dependency usage to styled-react; remove unused react-node_modules entries.
.prettierignore Ignore generated styled-react color-schemes.ts instead of react’s.
.changeset/styled-react-vendor-color-schemes.md Styled-react patch changeset for vendored legacy colorSchemes.
.changeset/remove-theme-color-schemes.md React major changeset for removing legacy JS theming surfaces.

Review details

  • Files reviewed: 24/38 changed files
  • Comments generated: 0
  • Review effort level: Low

@mattcosta7

Copy link
Copy Markdown
Contributor Author

vrt seems unrelated to schemes - maybe a flake or font loading?

@primer-integration

Copy link
Copy Markdown

⚠️ Integration PR Outdated

This integration PR does not have the latest commit from the primer/react PR.

Integration PR references: 3eafaec5aa614271b0abdc791d27081a1e40466c
Latest commit on primer/react PR: f3ed4f00f9ad9892126f8995ed94c9f2410d30e8

Please update the integration PR to reference the latest commit from the primer/react PR before reviewing workflow results.

@joshblack

Copy link
Copy Markdown
Member

Just a heads up, this was slated as a part of v39 since it's a major change and we tend to group them together to land them at once.

Just curious, are we importing this still in github-ui now that @primer/styled-react is no longer used there? If we are, do we happen to know why? I would assume this would be tree-shaken if it's not being used

@mattcosta7

mattcosta7 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Just a heads up, this was slated as a part of v39 since it's a major change and we tend to group them together to land them at once.

Just curious, are we importing this still in github-ui now that @primer/styled-react is no longer used there? If we are, do we happen to know why? I would assume this would be tree-shaken if it's not being used

The colorscheme object is merged into the theme, and merged in the regular ThemeProvider

Any app that uses a ThemeProvider from the main primer/react bundle incurs the cost of the entire legacy theme object - which can't be treeshaken, since it is used

Getting start still says to wrap with a ThemeProvider: https://primer.style/product/getting-started/react/ which imports the heavy legacy-theme and forces it into the bundle.

I marked it as a v39, so it can sit open for a while, but it's a very hefty bundle improvement.

I had done this iniitally as a spike in github-ui to see the cost, and just extracted that upstream since the work was already there

@mattcosta7

Copy link
Copy Markdown
Contributor Author

Just a heads up, this was slated as a part of v39 since it's a major change and we tend to group them together to land them at once.

Just curious, are we importing this still in github-ui now that @primer/styled-react is no longer used there? If we are, do we happen to know why? I would assume this would be tree-shaken if it's not being used

The base ThemeProvider imports defaultTheme which imports colorSchemes from legacy themes

So any app that use import {ThemeProvider} from '@primer/react' which is probably all of them? incurs the 200K or so gzup of that legacy-theme

@siddharthkp

siddharthkp commented Jul 23, 2026

Copy link
Copy Markdown
Member

Hi!

I'd like someone (or me) to verify that this is a safe change by testing it on local or preview before we merge. I have a feeling this isn't the kind of change that CI would catch

We could also look into feature flagging this change if the above exercise ^ does not give enough confidence

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Canary Release Apply this label when you want CI to create a canary release of the current PR 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.

5 participants