-
Couldn't load subscription status.
- Fork 640
Add SSR warnings on useMedia/useResponsiveValue #7070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: ed82b10 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
There was a problem hiding this 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
useMediatouseMediaUnsafeSSRacross 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 |
|
👋 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! |
7058304 to
3714548
Compare
Closes https://github.com/github/primer/issues/5283
Changelog
Introduce SSR (Server-Side Rendering) warnings to the
useMediaanduseResponsiveValuehooks in@primer/react, and renamesuseMediatouseMediaUnsafeSSRto 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
Testing & Reviewing
Merge checklist