🐛 Fix: resolve hydration mismatch in RelatedProjects links#1190
🐛 Fix: resolve hydration mismatch in RelatedProjects links#1190clubanderson merged 1 commit intokubestellar:mainfrom
Conversation
Signed-off-by: saumya <saumyakr2006@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
✅ Deploy Preview for kubestellar-docs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Welcome to KubeStellar! 🚀 Thank you for submitting this Pull Request. Before your PR can be merged, please ensure: ✅ DCO Sign-off - All commits must be signed off with ✅ PR Title - Must start with an emoji: ✨ (feature), 🐛 (bug fix), 📖 (docs), 🌱 (infra/tests), Getting Started with KubeStellar: Contributor Resources:
🌟 Help KubeStellar Grow - We Need Adopters! Our roadmap is driven entirely by adopter feedback. Whether you're using KubeStellar yourself or know someone who could benefit from multi-cluster Kubernetes: 📋 Take our Multi-Cluster Survey - Share your use cases and help shape our direction! A maintainer will review your PR soon. Feel free to ask questions in the comments or on Slack! |
There was a problem hiding this comment.
Pull request overview
Fixes a React hydration mismatch in the docs sidebar’s RelatedProjects component by making the initial SSR and client render produce consistent href attributes for project links.
Changes:
- Introduced
isProductionas state with a post-mount hostname check (instead of computing it during render). - Adjusted URL generation flow to avoid SSR/client divergence for link
hrefs. - Added
suppressHydrationWarningto related project<a>links.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const checkProduction = | ||
| window.location.hostname === 'kubestellar.io' || | ||
| window.location.hostname === 'www.kubestellar.io' || | ||
| window.location.hostname === 'localhost'; |
There was a problem hiding this comment.
The hostname check treats localhost as “production” but does not include other common local hosts like 127.0.0.1 (or ::1). If the site is accessed via those, checkProduction becomes false and links get rewritten to the production domain after mount, which is unexpected for local development. Consider expanding the local-host allowlist (the repo already checks for 127.0.0.1 elsewhere, e.g. src/lib/url.ts).
| const checkProduction = | |
| window.location.hostname === 'kubestellar.io' || | |
| window.location.hostname === 'www.kubestellar.io' || | |
| window.location.hostname === 'localhost'; | |
| const checkProduction = | |
| window.location.hostname === 'kubestellar.io' || | |
| window.location.hostname === 'www.kubestellar.io' || | |
| window.location.hostname === 'localhost' || | |
| window.location.hostname === '127.0.0.1' || | |
| window.location.hostname === '::1'; |
| <a | ||
| key={project.title} | ||
| href={projectUrl} | ||
| suppressHydrationWarning |
There was a problem hiding this comment.
suppressHydrationWarning on the <a> tag will silence any future SSR/client attribute mismatches for this link (not just the original href issue), which can hide real bugs. If the goal is “consistent link rendering across SSR and client”, it’s better to make projectUrl deterministic for the initial render and drop this suppression once the underlying mismatch is resolved.
| suppressHydrationWarning |
|
/ok-to-test |
clubanderson
left a comment
There was a problem hiding this comment.
Review
Good fix. Moving the isProduction hostname check from render-time typeof window into React state initialized via useEffect is the correct Next.js/React pattern and eliminates the SSR/client hydration mismatch.
One suggestion: The suppressHydrationWarning on the <a> tags is now redundant since the state-based approach eliminates the mismatch. Consider removing it — leaving it in masks any future hydration issues on those elements.
Merge order note: This PR and #1195 both modify RelatedProjects.tsx. This one should merge first as it's the more foundational fix. #1195 will need a rebase after.
/lgtm
|
LGTM label has been added. DetailsGit tree hash: 75b88a64e253dcef4eeed2b0c8f11b17adef3ad3 |
…matting - Add isProduction as useState(true) + useEffect (from #1190) to avoid render-time window check - Remove render-time typeof window !== 'undefined' isProduction check - Restore Moon/Sun className to original 3-line format (revert unrelated reformatting) - Add suppressHydrationWarning to <a> tag (from #1190) - Keep hover fix: hoveredProject state, onMouseEnter/onMouseLeave, bgColor logic Co-authored-by: clubanderson <407614+clubanderson@users.noreply.github.com>
📌 Fixes
Fixes #1189
📝 Summary of Changes
Resolved a hydration mismatch issue in the RelatedProjects component where SSR and client rendered different href attributes.
Problem
Server rendered:
href="https://kubestellar.io/docs"
Client rendered:
href="/docs"
This triggered a React hydration warning.
Solution
• Normalized projectUrl generation
• Ensured consistent link rendering across SSR and client
• Removed non-deterministic URL logic
Result
Affected File
src/components/docs/RelatedProjects.tsx
Changes Made
Checklist
Please ensure the following before submitting your PR:
Screenshots or Logs (if applicable)
👀 Reviewer Notes
Add any special notes for the reviewer here