Skip to content

fix(docs): prevent destructuring undefined loaderData - #1320

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/docs-loader-data-guard
Open

sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/docs-loader-data-guard

Conversation

@sentry

@sentry sentry Bot commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

This PR addresses a TypeError that occurs when Docs() components attempt to destructure content, filePath, and title from Route.useLoaderData() when the loader data is undefined.

The issue arises during client-side navigation, particularly when navigating to docs paths that implicitly redirect (e.g., a framework-less path redirecting to a framework-specific path). In such scenarios, the component can render before the loader has resolved its data or after a redirect has been initiated, leading to useLoaderData() returning undefined.

To fix this, a guard has been added to both src/routes/_library/$libraryId/$version.docs.$.tsx and src/routes/_library/$libraryId/$version.docs.framework.$framework.$.tsx.

Changes made:

  1. Route.useLoaderData() is now assigned to a loaderData variable.
  2. All React hooks (useParams, useLoaderData, useMatch, useLocation) are called before any conditional return to maintain stable hook order.
  3. An early return if (!loaderData) return null; is introduced. This prevents destructuring undefined and allows the component to gracefully handle the transient state where loader data is not yet available.
  4. The actual destructuring of content, filePath, and title now happens from the loaderData variable, only after it's confirmed to be defined.

This approach aligns with the existing optional chaining (loaderData?.title) already present in the head() and headers() functions within the same route, ensuring consistent handling of potentially undefined loader data.

Fixes TANSTACK-COM-52Z

@sentry <feedback>: Autofix iterates on these changes
@sentry stop iterating: Autofix stops iterating on this run

This PR was automatically generated by Sentry. You can adjust this setting at any time.

@coderabbitai

coderabbitai Bot commented Sep 30, 2026

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: ec921cb7-1fe0-43bb-8dfa-284d9e029e40

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
tanstack-com ca26fd9 Commit Preview URL

Branch Preview URL
Sep 30 2026, 11:08 PM

This branch has not been deployed

No deployments
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.

0 participants