Skip to content

Add next ThemeProvider without legacy JS theming - #8212

Merged
mattcosta7 merged 16 commits into
mainfrom
theming/remove-legacy-js-theme
Aug 11, 2026
Merged

Add next ThemeProvider without legacy JS theming#8212
mattcosta7 merged 16 commits into
mainfrom
theming/remove-legacy-js-theme

Conversation

@mattcosta7

@mattcosta7 mattcosta7 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Closes #

This PR adds a CSS-variable-based ThemeProvider at @primer/react/next so consumers can opt out of the large legacy JavaScript colorSchemes payload before the next major release. The root ThemeProvider keeps its existing behavior for compatibility and is deprecated in favor of the new entrypoint.

The two providers share one ThemeContext, useTheme, and internal state/rendering implementation. This supports incremental migration and mixed nesting while keeping deepmerge, the default JavaScript theme, and legacy color-scheme data out of the /next runtime graph.

@primer/styled-react now owns active generation of the legacy colorSchemes data it still requires. @primer/react retains a frozen compatibility snapshot for the deprecated root provider.

No visual change is expected. Both providers continue applying color schemes through the existing data-color-mode, data-light-theme, and data-dark-theme attributes.

Changelog

New

  • Export a CSS-variable-based ThemeProvider from @primer/react/next.
  • Export the shared useTheme and useColorSchemeVar hooks from @primer/react/next.

Changed

  • Deprecate the root ThemeProvider in favor of @primer/react/next while preserving its legacy JavaScript theme behavior.
  • Deprecate the theme and resolvedColorScheme properties returned by useTheme.
  • Keep root and /next providers interoperable through a shared context and hook.
  • Vendor active legacy theme generation into @primer/styled-react.

Removed

  • No consumer-facing APIs are removed in this release.

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

Consumers can migrate incrementally:

-import {ThemeProvider} from '@primer/react'
+import {ThemeProvider} from '@primer/react/next'

Existing useTheme imports remain compatible because both providers share the same context. Consumers of the legacy theme and resolvedColorScheme values should migrate away from those properties before switching providers.

A future major release can promote the /next provider to the root entrypoint and remove the deprecated JavaScript theme payload.

Testing & Reviewing

  • Full ESLint and CSS lint
  • Prettier formatting check
  • Classname coverage check
  • Full TypeScript validation: 15/15 tasks
  • Full unit suite: 2,596 tests passed
  • Full repository build: 5/5 tasks
  • @primer/react package build and publint
  • Verified emitted /next runtime modules do not import deepmerge, theme, colorSchemes, or legacy theme data

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: 6d1ee52

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 Minor
@primer/styled-react 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

primer Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

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

@mattcosta7 mattcosta7 changed the title Remove legacy JS theming (colorSchemes) from @primer/react Add next ThemeProvider without legacy JS theming Aug 5, 2026
@github-actions
github-actions Bot temporarily deployed to storybook-preview-8212 August 5, 2026 21:17 Inactive
@mattcosta7

Copy link
Copy Markdown
Contributor Author

VRT seems related to expected changes from - #8271

@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: 202dfdb9f6e75c6a2cef3e174f92e9bcb7caa1c3
Latest commit on primer/react PR: 6d1ee529710a6f45e040b5767f38b3aa17c51f5f

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

@mattcosta7
mattcosta7 enabled auto-merge August 10, 2026 17:08
@mattcosta7 mattcosta7 added integration-tests: skipped manually Changes in this PR do not require an integration test and removed integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm labels Aug 10, 2026
@primer
primer Bot disabled auto-merge August 11, 2026 13:43
@mattcosta7
mattcosta7 added this pull request to the merge queue Aug 11, 2026
Merged via the queue into main with commit 9ac9343 Aug 11, 2026
62 checks passed
@mattcosta7
mattcosta7 deleted the theming/remove-legacy-js-theme branch August 11, 2026 13:52
@primer primer Bot mentioned this pull request Aug 11, 2026
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: skipped manually Changes in this PR do not require an integration test major release breaking changes next major

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants