Skip to content

Move shared utilities out of React component files#7940

Merged
joshblack merged 1 commit into
mainfrom
joshblack/eslint-react-refresh/fix-utilities
Jun 12, 2026
Merged

Move shared utilities out of React component files#7940
joshblack merged 1 commit into
mainfrom
joshblack/eslint-react-refresh/fix-utilities

Conversation

@joshblack

@joshblack joshblack commented Jun 8, 2026

Copy link
Copy Markdown
Member

Closes #

No linked issue.

Extracts constants and utility helpers from component files into local constants.ts, utils.ts, or hook/component modules for React Refresh compatibility.

Changelog

New

  • Added local constants/utilities modules for FilteredActionList, KeybindingHint, Overlay, Timeline, Token, and UnderlineNav.
  • Split useMedia into a hook module with separate MatchMedia component/context modules.

Changed

  • Updated component files to consume the extracted helpers from non-component modules.

Removed

  • Removed non-component helper declarations from component implementation files.

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; internal refactor with existing public import paths preserved.

Testing & Reviewing

Review moved helpers by component area; useMedia keeps the existing extensionless import surface.

Merge checklist

@changeset-bot

changeset-bot Bot commented Jun 8, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 5b888fc

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 the staff Author is a staff member label 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.

@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 Jun 8, 2026
@joshblack joshblack changed the title Move React Refresh utility exports out of components Move shared utilities out of React component files Jun 8, 2026
@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
@github-actions github-actions Bot temporarily deployed to storybook-preview-7940 June 8, 2026 17:36 Inactive
@joshblack joshblack marked this pull request as ready for review 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 review from Copilot and llastflowers 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

Refactors several @primer/react components and hooks to move non-component constants/helpers into local constants.ts, utils.ts, or dedicated modules to improve React Refresh compatibility while preserving existing public exports/import surfaces.

Changes:

  • Extracted shared constants/utilities from component implementation files into colocated constants.ts / utils.ts modules (e.g. Overlay, Timeline, Token, UnderlineNav, FilteredActionList, KeybindingHint).
  • Kept existing public exports stable by re-exporting moved symbols from the original component modules.
  • Split MatchMedia/context out of useMedia.ts into separate hook modules while keeping useMedia’s import surface intact.
Show a summary per file
File Description
packages/react/src/UnderlineNav/utils.ts Introduces extracted getValidChildren helper.
packages/react/src/UnderlineNav/UnderlineNav.tsx Consumes extracted helper and re-exports it to preserve public API.
packages/react/src/Token/utils.ts Extracts isTokenInteractive helper.
packages/react/src/Token/constants.ts Extracts token size constants/types.
packages/react/src/Token/TokenBase.tsx Switches to extracted constants/utils and re-exports them.
packages/react/src/Timeline/constants.ts Extracts TimelineBadgeVariants constant.
packages/react/src/Timeline/Timeline.tsx Imports and re-exports extracted TimelineBadgeVariants.
packages/react/src/Overlay/constants.ts Extracts heightMap/widthMap constants.
packages/react/src/Overlay/Overlay.tsx Imports and re-exports extracted overlay dimension maps.
packages/react/src/KeybindingHint/components/utils.ts Extracts key-chord parsing/sorting + accessible string helpers.
packages/react/src/KeybindingHint/components/Chord.tsx Uses extracted chord utilities and re-exports accessibleChordString.
packages/react/src/KeybindingHint/components/Sequence.tsx Uses extracted sequence accessibility helper and re-exports it.
packages/react/src/hooks/MatchMediaContext.ts New module for MatchMediaContext and MediaQueryFeatures type.
packages/react/src/hooks/MatchMedia.tsx New module for MatchMedia component + shallow-stabilization helper.
packages/react/src/hooks/useMedia.ts Updated to consume extracted context and re-export MatchMedia.
packages/react/src/FilteredActionList/constants.ts Extracts loader type class + constants.
packages/react/src/FilteredActionList/FilteredActionListLoaders.tsx Imports and re-exports extracted loader symbols.

Copilot's findings

  • Files reviewed: 17/17 changed files
  • Comments generated: 1

Comment on lines +1 to +6
import React from 'react'

export const getValidChildren = (children: React.ReactNode) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return React.Children.toArray(children).filter(child => React.isValidElement(child)) as React.ReactElement<any>[]
}
@joshblack joshblack force-pushed the joshblack/eslint-react-refresh/fix-contexts branch from 8910bf9 to 23c0d01 Compare June 12, 2026 15:48
@joshblack joshblack force-pushed the joshblack/eslint-react-refresh/fix-utilities branch from c703182 to b61c265 Compare June 12, 2026 15:48
@github-actions github-actions Bot requested a deployment to storybook-preview-7940 June 12, 2026 15:52 Abandoned
@joshblack joshblack force-pushed the joshblack/eslint-react-refresh/fix-contexts branch from 23c0d01 to 2778f92 Compare June 12, 2026 15:54
@joshblack joshblack force-pushed the joshblack/eslint-react-refresh/fix-utilities branch from b61c265 to 5a97537 Compare June 12, 2026 15:54
@github-actions github-actions Bot requested a deployment to storybook-preview-7940 June 12, 2026 15:58 Abandoned
@github-actions github-actions Bot temporarily deployed to storybook-preview-7940 June 12, 2026 16:11 Inactive
@joshblack joshblack force-pushed the joshblack/eslint-react-refresh/fix-contexts branch from 2778f92 to af649ea Compare June 12, 2026 16:15
@joshblack joshblack force-pushed the joshblack/eslint-react-refresh/fix-utilities branch from 5a97537 to a00a887 Compare June 12, 2026 16:15
@github-actions github-actions Bot requested a deployment to storybook-preview-7940 June 12, 2026 16:19 Abandoned
@github-actions github-actions Bot temporarily deployed to storybook-preview-7940 June 12, 2026 16:31 Inactive
@joshblack joshblack added this pull request to the merge queue Jun 12, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue because a pull request earlier in the stack was removed Jun 12, 2026
@joshblack joshblack added this pull request to the merge queue Jun 12, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue because a pull request earlier in the stack was removed Jun 12, 2026
@joshblack joshblack added this pull request to the merge queue Jun 12, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue because a pull request earlier in the stack was removed Jun 12, 2026
@joshblack joshblack force-pushed the joshblack/eslint-react-refresh/fix-contexts branch from af649ea to da95916 Compare June 12, 2026 17:20
@joshblack joshblack force-pushed the joshblack/eslint-react-refresh/fix-utilities branch from a00a887 to 4176f8a Compare June 12, 2026 17:20
@github-actions github-actions Bot requested a deployment to storybook-preview-7940 June 12, 2026 17:24 Abandoned
@github-actions github-actions Bot temporarily deployed to storybook-preview-7940 June 12, 2026 17:35 Inactive
@joshblack joshblack added this pull request to the merge queue Jun 12, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to invalid changes in the merge commit Jun 12, 2026
Base automatically changed from joshblack/eslint-react-refresh/fix-contexts to main June 12, 2026 18:11
@joshblack joshblack force-pushed the joshblack/eslint-react-refresh/fix-utilities branch from 4176f8a to 5b888fc Compare June 12, 2026 18:12
@joshblack joshblack added this pull request to the merge queue Jun 12, 2026
Merged via the queue into main with commit e243edf Jun 12, 2026
50 checks passed
@joshblack joshblack deleted the joshblack/eslint-react-refresh/fix-utilities branch June 12, 2026 18:31
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