-
Notifications
You must be signed in to change notification settings - Fork 433
fix: handle undefined loaderData in head function for docs routes #2097
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?
fix: handle undefined loaderData in head function for docs routes #2097
Conversation
When a redirect is thrown in beforeLoad, the head function can be called before the loader runs, resulting in undefined loaderData. This causes a hydration error when accessing routes like /docs/faq that redirect to their default pages. The fix adds defensive checks to handle undefined loaderData gracefully by returning an empty meta array, allowing parent routes to provide default metadata. Co-Authored-By: john@hyprnote.com <john@hyprnote.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
✅ Deploy Preview for hyprnote-storybook ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
📝 WalkthroughWalkthroughTwo route files now defensively check if Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes
Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
✅ Deploy Preview for hyprnote ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
apps/web/src/routes/_view/company-handbook/$.tsx (1)
47-50: Defensiveheadguard correctly prevents runtime errors on missingloaderData.doc.Using
loaderData?.docplus an earlyreturn { meta: [] }avoids crashes whenloaderDatais undefined ordocis missing, while leaving existing meta generation unchanged whendocis present. This is consistent with the docs route pattern and is appropriate for the reported hydration issue.If you later want a non-empty fallback, you could return a generic site-level meta block here instead of an empty array, but that’s not required for this fix.
apps/web/src/routes/_view/docs/$.tsx (1)
47-50: Head function is now robust to missing loader data while preserving existing meta behavior.Reading
docvialoaderData?.docand returning{ meta: [] }when it’s absent prevents head-time exceptions in edge/hydration states, while leaving all URL/OG/Twitter metadata intact whendocexists. This aligns with the companion company-handbook route and directly addresses the undefinedloaderDataissue.If you ever want stronger SEO defaults, consider returning a generic docs meta config instead of an empty array in the fallback.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
apps/web/src/routes/_view/company-handbook/$.tsx(1 hunks)apps/web/src/routes/_view/docs/$.tsx(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{ts,tsx}: Avoid creating a bunch of types/interfaces if they are not shared. Especially for function props, just inline them instead.
Never do manual state management for form/mutation. Use useForm (from tanstack-form) and useQuery/useMutation (from tanstack-query) instead for 99% of cases. Avoid patterns like setError.
If there are many classNames with conditional logic, usecn(import from@hypr/utils). It is similar toclsx. Always pass an array and split by logical grouping.
Usemotion/reactinstead offramer-motion.
Files:
apps/web/src/routes/_view/docs/$.tsxapps/web/src/routes/_view/company-handbook/$.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: Redirect rules - hyprnote
- GitHub Check: Header rules - hyprnote
- GitHub Check: Pages changed - hyprnote
- GitHub Check: Devin
- GitHub Check: fmt
- GitHub Check: ci
Summary
Fixes the white page / hydration error on
/docs/faq(and similar redirect-only doc routes). The error was:Root cause: When
beforeLoadthrows a redirect (e.g.,/docs/faq→/docs/faq/general), theheadfunction can be called before the loader runs, resulting inloaderDatabeing undefined. The code was using non-null assertions (loaderData!) which crashed.Fix: Changed to optional chaining (
loaderData?.doc) with an early return of empty meta array whendocis undefined. Applied to both/docs/$and/company-handbook/$routes which share the same pattern.Review & Testing Checklist for Human
/docs/faqand verify it no longer shows a white page (should redirect to/docs/faq/general)/docs/proand verify it still works correctly/company-handbook/about)Notes