Skip to content

Conversation

@hectahertz
Copy link
Contributor

@hectahertz hectahertz commented Oct 24, 2025

Closes https://github.com/github/primer/issues/5283

Changelog

Introduce SSR (Server-Side Rendering) warnings to the useMedia and useResponsiveValue hooks in @primer/react, and renames useMedia to useMediaUnsafeSSR to improve clarity around SSR compatibility.

The main focus is to warn developers about potential hydration mismatches when using these hooks without a default state during SSR, and to encourage safer alternatives.

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

Testing & Reviewing

Merge checklist

@hectahertz hectahertz requested a review from a team as a code owner October 24, 2025 13:53
@changeset-bot
Copy link

changeset-bot bot commented Oct 24, 2025

🦋 Changeset detected

Latest commit: ed82b10

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 Patch
@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

Copy link
Contributor

Copilot AI left a comment

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 renames the useMedia hook to useMediaUnsafeSSR to better communicate the SSR safety implications of using this hook without a defaultState parameter. The rename helps developers understand that this hook can cause hydration mismatches when rendering on the server without proper configuration.

Key changes:

  • Renamed useMedia to useMediaUnsafeSSR across the codebase
  • Added warning documentation about SSR compatibility to both the hook and its usage in useResponsiveValue

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/react/src/hooks/useResponsiveValue.ts Updated to use useMediaUnsafeSSR and added SSR compatibility warning in documentation
packages/react/src/hooks/useMediaUnsafeSSR.tsx Renamed hook from useMedia to useMediaUnsafeSSR and updated documentation references
packages/react/src/hooks/tests/useMedia.test.tsx Updated test file to use renamed useMediaUnsafeSSR hook

@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 Oct 24, 2025
@github-actions
Copy link
Contributor

👋 Hi, this pull request contains changes to the source code that github/github depends on. If you are GitHub staff, we recommend testing these changes with github/github using the integration workflow. Thanks!

@hectahertz hectahertz changed the title Hectahertz/usemedia-warnings WIP: SSR warnings on useMedia/useResponsiveValue Oct 24, 2025
@hectahertz hectahertz marked this pull request as draft October 24, 2025 13:55
@hectahertz hectahertz removed the request for review from joshblack October 24, 2025 13:55
@github-actions github-actions bot temporarily deployed to storybook-preview-7070 October 24, 2025 14:06 Inactive
@hectahertz hectahertz force-pushed the hectahertz/usemedia-warnings branch from 7058304 to 3714548 Compare October 28, 2025 15:57
@github-actions github-actions bot requested a deployment to storybook-preview-7070 October 28, 2025 16:01 Abandoned
@github-actions github-actions bot temporarily deployed to storybook-preview-7070 October 28, 2025 16:11 Inactive
@hectahertz hectahertz changed the title WIP: SSR warnings on useMedia/useResponsiveValue Add SSR warnings on useMedia/useResponsiveValue Oct 28, 2025
@hectahertz hectahertz marked this pull request as ready for review October 28, 2025 16:56
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants