Skip to content

fix: preserve null values in useResponsiveValue - #8759

Open
nemo-crypto wants to merge 1 commit into
primer:mainfrom
nemo-crypto:fix/responsive-value-null
Open

nemo-crypto wants to merge 1 commit into
primer:mainfrom
nemo-crypto:fix/responsive-value-null

Conversation

@nemo-crypto

Copy link
Copy Markdown

Passing null to the public useResponsiveValue hook currently throws TypeError: Cannot convert undefined or null to object during rendering. Its generic API accepts non-responsive values, but isResponsiveValue treats null as an object and calls Object.keys(null).

For example, useResponsiveValue(null, 'fallback') now returns null unchanged, consistent with the hook's handling of other non-responsive values. Add a null guard before inspecting the breakpoint keys; breakpoint selection and fallback behavior remain unchanged.

Changelog

New

  • Regression tests for an initial null value and switching from responsive values to null and back.

Changed

  • Preserve null non-responsive values without throwing.
  • Include a patch changeset for @primer/react.

Removed

  • None.

Rollout strategy

  • No changes needed in github/github-ui
  • Needs changes in github/github-ui
  • Ships with feature flag(s)
  • Not sure
  • None

Testing & Reviewing

  • Both new tests fail on the original implementation at Object.keys(null) and pass with the guard.
  • Targeted useResponsiveValue and useMedia tests: 12 passed in Chromium.
  • Full npm test -- --run after building: 3,095 passed, 3 skipped, 10 todo; one timeout in the existing deprecated DialogV1 test Returns focus to returnFocusRef on escape. Rerunning that suite alone passed all 9 tests.
  • npm run build
  • npm run type-check
  • npm run lint:fix
  • npm run lint:css
  • npm run format:diff

Prepared with AI assistance; the failure and fix were verified locally.

@nemo-crypto
nemo-crypto requested a review from a team as a code owner November 16, 2026 01:44
@changeset-bot

changeset-bot Bot commented Nov 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4d9631a

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

This PR includes changesets to release 1 package
Name Type
@primer/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

This branch was successfully deployed

1 active deployment
github-pages — 4d9631a7 Deployed Nov 16, 2026 by nemo-crypto via deploy-preview #30628
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants