Skip to content

Commit 617f052

Browse files
authored
Add jsdocs for SSR/Framework components (#14013)
1 parent d959d86 commit 617f052

File tree

12 files changed

+147
-146
lines changed

12 files changed

+147
-146
lines changed

.eslintrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
"files": [
2525
"packages/react-router/lib/components.tsx",
2626
"packages/react-router/lib/hooks.tsx",
27-
"packages/react-router/lib/dom/lib.tsx"
27+
"packages/react-router/lib/dom/lib.tsx",
28+
"packages/react-router/lib/dom/ssr/components.tsx",
29+
"packages/react-router/lib/dom/ssr/server.tsx",
30+
"packages/react-router/lib/dom-export/hydrated-router.tsx"
2831
],
2932
"plugins": ["jsdoc"],
3033
"rules": {

.github/workflows/docs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ jobs:
5151
pnpm run docs:jsdoc --path packages/react-router/lib/components.tsx --write
5252
pnpm run docs:jsdoc --path packages/react-router/lib/hooks.tsx --write
5353
pnpm run docs:jsdoc --path packages/react-router/lib/dom/lib.tsx --write
54+
pnpm run docs:jsdoc --path packages/react-router/lib/dom/ssr/components.tsx --write
55+
pnpm run docs:jsdoc --path packages/react-router/lib/dom/ssr/server.tsx --write
56+
pnpm run docs:jsdoc --path packages/react-router/lib/dom-export/hydrated-router.tsx --write
5457
5558
- name: 💪 Commit
5659
run: |

docs/api/components/ServerRouter.md

Lines changed: 0 additions & 33 deletions
This file was deleted.

docs/api/data-routers/HydratedRouter.md

Lines changed: 0 additions & 17 deletions
This file was deleted.

docs/api/data-routers/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
---
22
title: Data Routers
3+
order: 5
34
---
4-

docs/api/declarative-routers/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
---
22
title: Declarative Routers
3+
order: 6
34
---
4-

docs/api/framework-routers/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
title: Framework Routers
3+
order: 4
4+
---

docs/api/rsc/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
---
22
title: RSC (Unstable)
3+
order: 7
34
---

packages/react-router/lib/dom-export/hydrated-router.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,17 @@ interface HydratedRouterProps {
217217
}
218218

219219
/**
220-
* Framework-mode router component to be used in `entry.client.tsx` to hydrate a
221-
* router from a `ServerRouter`
220+
* Framework-mode router component to be used to to hydrate a router from a
221+
* `ServerRouter`. See [`entry.client.tsx`](../api/framework-conventions/entry.client.tsx).
222222
*
223-
* @category Component Routers
223+
* @public
224+
* @category Framework Routers
225+
* @mode framework
226+
* @param props Props
227+
* @param props.unstable_getContext Context object to passed through to
228+
* {@link createBrowserRouter} and made available to `clientLoader`/`clientAction`
229+
* functions
230+
* @returns A React element that represents the hydrated application.
224231
*/
225232
export function HydratedRouter(props: HydratedRouterProps) {
226233
if (!router) {

packages/react-router/lib/dom/ssr/components.tsx

Lines changed: 104 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -213,26 +213,30 @@ function getActiveMatches(
213213
}
214214

215215
/**
216-
Renders all of the `<link>` tags created by route module {@link LinksFunction} export. You should render it inside the `<head>` of your document.
217-
218-
```tsx
219-
import { Links } from "react-router";
220-
221-
export default function Root() {
222-
return (
223-
<html>
224-
<head>
225-
<Links />
226-
</head>
227-
<body></body>
228-
</html>
229-
);
230-
}
231-
```
232-
233-
@category Components
216+
* Renders all of the `<link>` tags created by the route module
217+
* [`links`](../../start/framework/route-module#links) export. You should render
218+
* it inside the `<head>` of your document.
219+
*
220+
* @example
221+
* import { Links } from "react-router";
222+
*
223+
* export default function Root() {
224+
* return (
225+
* <html>
226+
* <head>
227+
* <Links />
228+
* </head>
229+
* <body></body>
230+
* </html>
231+
* );
232+
* }
233+
*
234+
* @public
235+
* @category Components
236+
* @mode framework
237+
* @returns A collection of React elements for `<link>` tags
234238
*/
235-
export function Links() {
239+
export function Links(): React.JSX.Element {
236240
let { isSpaMode, manifest, routeModules, criticalCss } =
237241
useFrameworkContext();
238242
let { errors, matches: routerMatches } = useDataRouterStateContext();
@@ -264,17 +268,28 @@ export function Links() {
264268
}
265269

266270
/**
267-
Renders `<link rel=prefetch|modulepreload>` tags for modules and data of another page to enable an instant navigation to that page. {@link LinkProps.prefetch | `<Link prefetch>`} uses this internally, but you can render it to prefetch a page for any other reason.
268-
269-
```tsx
270-
import { PrefetchPageLinks } from "react-router"
271-
272-
<PrefetchPageLinks page="/absolute/path" />
273-
```
274-
275-
For example, you may render one of this as the user types into a search field to prefetch search results before they click through to their selection.
276-
277-
@category Components
271+
* Renders `<link rel=prefetch|modulepreload>` tags for modules and data of
272+
* another page to enable an instant navigation to that page.
273+
* [`<Link prefetch>`](../../components/Link#prefetch) uses this internally, but
274+
* you can render it to prefetch a page for any other reason.
275+
*
276+
* For example, you may render one of this as the user types into a search field
277+
* to prefetch search results before they click through to their selection.
278+
*
279+
* @example
280+
* import { PrefetchPageLinks } from "react-router";
281+
*
282+
* <PrefetchPageLinks page="/absolute/path" />
283+
*
284+
* @public
285+
* @category Components
286+
* @mode framework
287+
* @param props Props
288+
* @param props.page The absolute path of the page to prefetch, e.g. `/absolute/path`.
289+
* @param props.dataLinkProps Additional props to pass to the
290+
* [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/link)
291+
* tag, such as `crossOrigin`, `integrity`, `rel`, etc.
292+
* @returns A collection of React elements for `<link>` tags
278293
*/
279294
export function PrefetchPageLinks({
280295
page,
@@ -446,25 +461,29 @@ function PrefetchPageLinksImpl({
446461
}
447462

448463
/**
449-
Renders all the `<meta>` tags created by route module {@link MetaFunction} exports. You should render it inside the `<head>` of your HTML.
450-
451-
```tsx
452-
import { Meta } from "react-router";
453-
454-
export default function Root() {
455-
return (
456-
<html>
457-
<head>
458-
<Meta />
459-
</head>
460-
</html>
461-
);
462-
}
463-
```
464-
465-
@category Components
464+
* Renders all the `<meta>` tags created by the route module
465+
* [`meta`](../../start/framework/route-module#meta) exports. You should render
466+
* it inside the `<head>` of your HTML.
467+
*
468+
* @example
469+
* import { Meta } from "react-router";
470+
*
471+
* export default function Root() {
472+
* return (
473+
* <html>
474+
* <head>
475+
* <Meta />
476+
* </head>
477+
* </html>
478+
* );
479+
* }
480+
*
481+
* @public
482+
* @category Components
483+
* @mode framework
484+
* @returns A collection of React elements for `<meta>` tags
466485
*/
467-
export function Meta() {
486+
export function Meta(): React.JSX.Element {
468487
let { isSpaMode, routeModules } = useFrameworkContext();
469488
let {
470489
errors,
@@ -604,14 +623,14 @@ function isValidMetaTag(tagName: unknown): tagName is "meta" | "link" {
604623
let isHydrated = false;
605624

606625
/**
607-
A couple common attributes:
608-
609-
- `<Scripts crossOrigin>` for hosting your static assets on a different server than your app.
610-
- `<Scripts nonce>` to support a [content security policy for scripts](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src) with [nonce-sources](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources#sources) for your `<script>` tags.
611-
612-
You cannot pass through attributes such as `async`, `defer`, `src`, `type`, `noModule` because they are managed by React Router internally.
613-
614-
@category Types
626+
* A couple common attributes:
627+
*
628+
* - `<Scripts crossOrigin>` for hosting your static assets on a different server than your app.
629+
* - `<Scripts nonce>` to support a [content security policy for scripts](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src) with [nonce-sources](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources#sources) for your `<script>` tags.
630+
*
631+
* You cannot pass through attributes such as `async`, `defer`, `src`, `type`, `noModule` because they are managed by React Router internally.
632+
*
633+
* @category Types
615634
*/
616635
export type ScriptsProps = Omit<
617636
React.HTMLProps<HTMLScriptElement>,
@@ -632,28 +651,36 @@ export type ScriptsProps = Omit<
632651
};
633652

634653
/**
635-
Renders the client runtime of your app. It should be rendered inside the `<body>` of the document.
636-
637-
```tsx
638-
import { Scripts } from "react-router";
639-
640-
export default function Root() {
641-
return (
642-
<html>
643-
<head />
644-
<body>
645-
<Scripts />
646-
</body>
647-
</html>
648-
);
649-
}
650-
```
651-
652-
If server rendering, you can omit `<Scripts/>` and the app will work as a traditional web app without JavaScript, relying solely on HTML and browser behaviors.
653-
654-
@category Components
654+
* Renders the client runtime of your app. It should be rendered inside the
655+
* `<body>` of the document.
656+
*
657+
* If server rendering, you can omit `<Scripts/>` and the app will work as a
658+
* traditional web app without JavaScript, relying solely on HTML and browser
659+
* behaviors.
660+
*
661+
* @example
662+
* import { Scripts } from "react-router";
663+
*
664+
* export default function Root() {
665+
* return (
666+
* <html>
667+
* <head />
668+
* <body>
669+
* <Scripts />
670+
* </body>
671+
* </html>
672+
* );
673+
* }
674+
*
675+
* @public
676+
* @category Components
677+
* @mode framework
678+
* @param props Props for the
679+
* [`<script>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script)
680+
* tag, such as `crossOrigin`, `nonce`, etc.
681+
* @returns A collection of React elements for `<script>` tags
655682
*/
656-
export function Scripts(props: ScriptsProps) {
683+
export function Scripts(props: ScriptsProps): React.JSX.Element | null {
657684
let {
658685
manifest,
659686
serverHandoffString,

0 commit comments

Comments
 (0)