Skip to content

Conversation

@tannerlinsley
Copy link
Collaborator

@tannerlinsley tannerlinsley commented Oct 20, 2025

Add JSDoc annotations to core public APIs to improve self-documentation.

The task requested adding 5-10 concise JSDoc annotations to core, publicly documented APIs, prioritizing hooks and components, without altering existing JSDoc. This PR adds descriptions and parameter explanations to useRouter, useSearch, useParams, useRouterState, RouterContextProvider, and RouterProvider.


Open in Cursor Open in Web

Summary by CodeRabbit

  • Documentation

    • Added comprehensive JSDoc documentation to RouterProvider, Link component, and router hooks (useParams, useRouter, useSearch, useRouterState) for improved developer clarity and guidance.
  • New Features

    • useRouterState hook now supports configurable structural sharing parameters for optimized state comparison and selection behavior.

@cursor
Copy link

cursor bot commented Oct 20, 2025

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 20, 2025

Walkthrough

Documentation enhancements across React Router hooks through JSDoc additions and clarified comments. The useRouterState hook signature is updated with a new generic type parameter for structural sharing support, while preserving all existing runtime behavior.

Changes

Cohort / File(s) Summary
Documentation additions
packages/react-router/src/RouterProvider.tsx, packages/react-router/src/useParams.tsx, packages/react-router/src/useRouter.tsx, packages/react-router/src/useSearch.tsx
Added comprehensive JSDoc blocks describing hook purpose, parameters, options, and return values without altering function signatures or runtime behavior
Documentation clarification
packages/react-router/src/link.tsx
Updated descriptive header from "Non-obvious props include:" to "Props:" in component documentation
Type signature enhancement
packages/react-router/src/useRouterState.tsx
Added new generic type parameter TStructuralSharing (default boolean) to useRouterState hook signature; runtime logic preserved with structural sharing behavior controlled through options

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Majority of changes are homogeneous documentation additions with consistent patterns. The type parameter addition to useRouterState is isolated to a single file with no apparent breaking changes to existing behavior.

Suggested labels

documentation

Poem

Hops through the hooks with care so fine, 🐰
JSDoc blooms in every line,
Types now flexed with sharing grace,
Documentation lights the place,
The code flows clear, a treat sublime!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Add JSDoc to public API" directly aligns with the primary focus of this pull request. Reviewing the file-level changes, five of the six modified files involve pure JSDoc documentation additions (RouterProvider.tsx, useParams.tsx, useRouter.tsx, useSearch.tsx, and link.tsx documentation update), which constitute the vast majority of the changeset. While useRouterState.tsx includes a signature enhancement with a new generic parameter, it is still part of the broader documentation effort described in the PR objectives. The title is concise, specific, and clearly conveys the main intent to improve the self-documentation of core public APIs through JSDoc annotations.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ 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 cursor/add-jsdoc-to-public-api-64fa

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

@nx-cloud
Copy link

nx-cloud bot commented Oct 20, 2025

View your CI Pipeline Execution ↗ for commit 27284ce

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 4m 39s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 1m 24s View ↗

☁️ Nx Cloud last updated this comment at 2025-10-20 23:32:30 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 20, 2025

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@5555

@tanstack/directive-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@5555

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@5555

@tanstack/history

npm i https://pkg.pr.new/TanStack/router/@tanstack/history@5555

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@5555

@tanstack/react-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@5555

@tanstack/react-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@5555

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@5555

@tanstack/react-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@5555

@tanstack/react-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@5555

@tanstack/react-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@5555

@tanstack/router-cli

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@5555

@tanstack/router-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@5555

@tanstack/router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@5555

@tanstack/router-devtools-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@5555

@tanstack/router-generator

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@5555

@tanstack/router-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@5555

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@5555

@tanstack/router-utils

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@5555

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@5555

@tanstack/server-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@5555

@tanstack/solid-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@5555

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@5555

@tanstack/solid-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-ssr-query@5555

@tanstack/solid-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@5555

@tanstack/solid-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@5555

@tanstack/solid-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@5555

@tanstack/start-client-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@5555

@tanstack/start-plugin-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@5555

@tanstack/start-server-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@5555

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@5555

@tanstack/start-storage-context

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@5555

@tanstack/valibot-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@5555

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@5555

@tanstack/zod-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@5555

commit: 27284ce

@tannerlinsley tannerlinsley marked this pull request as ready for review October 21, 2025 03:29
@tannerlinsley tannerlinsley merged commit 76dc565 into main Oct 21, 2025
5 of 6 checks passed
@tannerlinsley tannerlinsley deleted the cursor/add-jsdoc-to-public-api-64fa branch October 21, 2025 03:32
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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/react-router/src/link.tsx (1)

542-549: Clarify that the list is non-exhaustive (was previously accurate).

Changing the heading to “Props:” implies a complete list, but the bullets remain a subset (e.g., omits disabled, replace, target, reloadDocument, etc.). Please either revert to a non-exhaustive label or expand/clarify.

Suggested tweak:

- * Props:
+ * Key props (non‑exhaustive):

Optionally, add a note about disabled semantics (removed for native , respected when rendering via _asChild).

🧹 Nitpick comments (6)
packages/react-router/src/RouterProvider.tsx (2)

10-13: Nice concise description. Consider annotating params for quick IntelliSense.

Add brief @param entries for router and notable props (e.g., context) and a one-liner about “props update router.options each render (shallow-merged)”. Improves clarity when hovering in editors.


51-59: Docs read well; a tiny usage example would help.

Add a minimal snippet showing <RouterProvider router={router} /> with a comment that it should wrap the app root. Optional but practical.

packages/react-router/src/useParams.tsx (1)

64-75: Solid overview. Add context and a tiny example for completeness.

  • Add a note: “Must be used within a RouterProvider.”
  • Optional: a one-liner example with select to show projection usage.

Everything else looks good.

packages/react-router/src/useSearch.tsx (1)

64-75: Clear and consistent. Consider adding two small touches.

  • Mention it must be used within a RouterProvider.
  • Include a short select example to show memoized projection.

Nice work.

packages/react-router/src/useRouter.tsx (1)

6-15: Add optional example to JSDoc for better discoverability.

The @link URL is correct and verified. Consider adding @example const router = useRouter() to the JSDoc block to help developers discover the hook's basic usage pattern.

packages/react-router/src/useRouterState.tsx (1)

31-42: JSDoc improvements suggested; documentation URL verified but can be more specific.

The JSDoc addition is helpful. To enhance IDE tooling and reader clarity:

  • Add @template, @param, and @returns tags for better type awareness
  • Document that structuralSharing defaults to router.options.defaultStructuralSharing
  • Note that select should be a stable function (e.g., via useCallback) to avoid unnecessary recomputation
  • Update the docs link from latest to v1 for consistency with the current TanStack Router versioning

Suggested edit:

-/**
- * Subscribe to the router's state store with optional selection and
- * structural sharing for render optimization.
- *
- * Options:
- * - `select`: Project the full router state to a derived slice
- * - `structuralSharing`: Replace-equal semantics for stable references
- * - `router`: Read state from a specific router instance instead of context
- *
- * @returns The selected router state (or the full state by default).
- * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useRouterStateHook
- */
+/**
+ * Subscribe to the router's state store with optional selection and
+ * structural sharing for render optimization.
+ *
+ * Options:
+ * - `select`: Project the full router state to a derived slice. Prefer a stable function (e.g. via `useCallback`).
+ * - `structuralSharing`: Replace-equal semantics for stable references.
+ *   Defaults to `router.options.defaultStructuralSharing`.
+ * - `router`: Read state from a specific router instance instead of context.
+ *
+ * @template TRouter, TSelected, TStructuralSharing
+ * @param opts Options to customize selection, structural sharing, and router source.
+ * @returns The selected router state, or the full state when no selector is provided.
+ * @link https://tanstack.com/router/v1/docs/framework/react/api/router/useRouterStateHook
+ */
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3eccdeb and 27284ce.

📒 Files selected for processing (6)
  • packages/react-router/src/RouterProvider.tsx (2 hunks)
  • packages/react-router/src/link.tsx (1 hunks)
  • packages/react-router/src/useParams.tsx (1 hunks)
  • packages/react-router/src/useRouter.tsx (1 hunks)
  • packages/react-router/src/useRouterState.tsx (1 hunks)
  • packages/react-router/src/useSearch.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use TypeScript in strict mode with extensive type safety across the codebase

Files:

  • packages/react-router/src/useRouter.tsx
  • packages/react-router/src/link.tsx
  • packages/react-router/src/RouterProvider.tsx
  • packages/react-router/src/useSearch.tsx
  • packages/react-router/src/useRouterState.tsx
  • packages/react-router/src/useParams.tsx
packages/{react-router,solid-router}/**

📄 CodeRabbit inference engine (AGENTS.md)

Implement React and Solid bindings/components only in packages/react-router/ and packages/solid-router/

Files:

  • packages/react-router/src/useRouter.tsx
  • packages/react-router/src/link.tsx
  • packages/react-router/src/RouterProvider.tsx
  • packages/react-router/src/useSearch.tsx
  • packages/react-router/src/useRouterState.tsx
  • packages/react-router/src/useParams.tsx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants