Skip to content

Conversation

@ComputelessComputer
Copy link
Collaborator

@ComputelessComputer ComputelessComputer commented Dec 3, 2025

Summary

Fixes the white page / hydration error on /docs/faq (and similar redirect-only doc routes). The error was:

Error during hydration for route /_view/docs/$: TypeError: Cannot destructure property 'doc' of 't' as it is undefined.

Root cause: When beforeLoad throws a redirect (e.g., /docs/faq/docs/faq/general), the head function can be called before the loader runs, resulting in loaderData being 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 when doc is undefined. Applied to both /docs/$ and /company-handbook/$ routes which share the same pattern.

Review & Testing Checklist for Human

  • Navigate to /docs/faq and verify it no longer shows a white page (should redirect to /docs/faq/general)
  • Navigate to /docs/pro and verify it still works correctly
  • Check if other routes with similar redirect patterns need the same fix (e.g., /company-handbook/about)

Notes

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-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@netlify
Copy link

netlify bot commented Dec 3, 2025

Deploy Preview for hyprnote-storybook ready!

Name Link
🔨 Latest commit a8b4861
🔍 Latest deploy log https://app.netlify.com/projects/hyprnote-storybook/deploys/69301dc09ff9d20008634f2d
😎 Deploy Preview https://deploy-preview-2097--hyprnote-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 3, 2025

📝 Walkthrough

Walkthrough

Two route files now defensively check if loaderData.doc exists before accessing it in the head function. If missing, the function returns early with empty metadata. This replaces non-null assertions with optional chaining and guard clauses, preventing runtime errors when doc is undefined.

Changes

Cohort / File(s) Summary
Defensive guard additions in head functions
apps/web/src/routes/_view/company-handbook/$.tsx, apps/web/src/routes/_view/docs/$.tsx
Added early return guard (if (!doc) return { meta: [] }) when loaderData?.doc is falsy in head function. Replaced non-null assertion with optional chaining to prevent crashes when doc is missing.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

  • Consistent pattern applied across two files
  • Simple defensive guard additions with no complex logic
  • Straightforward null-check and early return pattern

Possibly related PRs

Suggested reviewers

  • yujonglee

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing undefined loaderData handling in the head function for docs routes, which is the core issue resolved in both modified files.
Description check ✅ Passed The description is directly related to the changeset, explaining the root cause of the bug (hydration error when loaderData is undefined), the fix applied (optional chaining with early return), and which files were affected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch devin/1764760754-fix-docs-hydration-error

Comment @coderabbitai help to get the list of available commands and usage tips.

@netlify
Copy link

netlify bot commented Dec 3, 2025

Deploy Preview for hyprnote ready!

Name Link
🔨 Latest commit a8b4861
🔍 Latest deploy log https://app.netlify.com/projects/hyprnote/deploys/69301dc025fd8900080a4957
😎 Deploy Preview https://deploy-preview-2097--hyprnote.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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: Defensive head guard correctly prevents runtime errors on missing loaderData.doc.

Using loaderData?.doc plus an early return { meta: [] } avoids crashes when loaderData is undefined or doc is missing, while leaving existing meta generation unchanged when doc is 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 doc via loaderData?.doc and returning { meta: [] } when it’s absent prevents head-time exceptions in edge/hydration states, while leaving all URL/OG/Twitter metadata intact when doc exists. This aligns with the companion company-handbook route and directly addresses the undefined loaderData issue.

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

📥 Commits

Reviewing files that changed from the base of the PR and between d847251 and a8b4861.

📒 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, use cn (import from @hypr/utils). It is similar to clsx. Always pass an array and split by logical grouping.
Use motion/react instead of framer-motion.

Files:

  • apps/web/src/routes/_view/docs/$.tsx
  • apps/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

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