Skip to content

Commit 80ea7e0

Browse files
committed
Update docs @link resolution to better handle unstable APIs
1 parent 703eb02 commit 80ea7e0

File tree

8 files changed

+25
-18
lines changed

8 files changed

+25
-18
lines changed

docs/api/data-routers/createBrowserRouter.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ the `submitting` portion of the navigation for non-`GET` requests.
610610
### opts.window
611611

612612
[`Window`](https://developer.mozilla.org/en-US/docs/Web/API/Window) object
613-
override — defaults to the global `window` instance.
613+
override. Defaults to the global `window` instance.
614614

615615
## Returns
616616

docs/api/data-routers/createHashRouter.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ the `submitting` portion of the navigation for non-`GET` requests.
609609
### opts.window
610610
611611
[`Window`](https://developer.mozilla.org/en-US/docs/Web/API/Window) object
612-
override — defaults to the global `window` instance.
612+
override. Defaults to the global `window` instance.
613613
614614
## Returns
615615

docs/api/declarative-routers/BrowserRouter.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ Application basename
4444
### window
4545

4646
[`Window`](https://developer.mozilla.org/en-US/docs/Web/API/Window) object
47-
overridedefaults to the global `window` instance
47+
override. Defaults to the global `window` instance
4848

docs/api/declarative-routers/HashRouter.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ Application basename
4545
### window
4646

4747
[`Window`](https://developer.mozilla.org/en-US/docs/Web/API/Window) object
48-
overridedefaults to the global `window` instance
48+
override. Defaults to the global `window` instance
4949

docs/api/rsc/RSCStaticRouter.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ to release notes for relevant changes.</docs-warning>
3131
[Reference Documentation ↗](https://api.reactrouter.com/v7/functions/react_router.unstable_RSCStaticRouter.html)
3232

3333
Pre-renders an [`unstable_RSCPayload`](https://api.reactrouter.com/v7/types/react_router.unstable_RSCPayload.html) to HTML. Usually used in
34-
[`unstable_routeRSCServerRequest`](https://api.reactrouter.com/v7/functions/react_router.unstable_routeRSCServerRequest.html)'s `renderHTML` callback.
34+
[`unstable_routeRSCServerRequest`](../rsc/routeRSCServerRequest)'s `renderHTML` callback.
3535

3636
```tsx
3737
import { createFromReadableStream } from "@vitejs/plugin-rsc/ssr";
@@ -70,5 +70,5 @@ function RSCStaticRouter({ getPayload }: RSCStaticRouterProps)
7070
### getPayload
7171

7272
A function that starts decoding of the [`unstable_RSCPayload`](https://api.reactrouter.com/v7/types/react_router.unstable_RSCPayload.html). Usually passed
73-
through from [`unstable_routeRSCServerRequest`](https://api.reactrouter.com/v7/functions/react_router.unstable_routeRSCServerRequest.html)'s `renderHTML`.
73+
through from [`unstable_routeRSCServerRequest`](../rsc/routeRSCServerRequest)'s `renderHTML`.
7474

docs/api/rsc/routeRSCServerRequest.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Whether to hydrate the server response with the RSC payload. Defaults to `true`.
9898

9999
### opts.renderHTML
100100

101-
A function that renders the [`unstable_RSCPayload`](https://api.reactrouter.com/v7/types/react_router.unstable_RSCPayload.html) to HTML, usually using a [`<RSCStaticRouter>`](https://api.reactrouter.com/v7/functions/react_router.unstable_RSCStaticRouter.html).
101+
A function that renders the [`unstable_RSCPayload`](https://api.reactrouter.com/v7/types/react_router.unstable_RSCPayload.html) to HTML, usually using a [`<RSCStaticRouter>`](../rsc/RSCStaticRouter).
102102

103103
### opts.request
104104

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ export interface DOMRouterOpts {
701701
patchRoutesOnNavigation?: PatchRoutesOnNavigationFunction;
702702
/**
703703
* [`Window`](https://developer.mozilla.org/en-US/docs/Web/API/Window) object
704-
* override — defaults to the global `window` instance.
704+
* override. Defaults to the global `window` instance.
705705
*/
706706
window?: Window;
707707
}
@@ -860,7 +860,7 @@ export interface BrowserRouterProps {
860860
children?: React.ReactNode;
861861
/**
862862
* [`Window`](https://developer.mozilla.org/en-US/docs/Web/API/Window) object
863-
* override — defaults to the global `window` instance
863+
* override. Defaults to the global `window` instance
864864
*/
865865
window?: Window;
866866
}
@@ -928,7 +928,7 @@ export interface HashRouterProps {
928928
children?: React.ReactNode;
929929
/**
930930
* [`Window`](https://developer.mozilla.org/en-US/docs/Web/API/Window) object
931-
* override — defaults to the global `window` instance
931+
* override. Defaults to the global `window` instance
932932
*/
933933
window?: Window;
934934
}

scripts/docs.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -699,20 +699,27 @@ async function getSignature(code: string) {
699699
* @returns Text with {@link ...} tags replaced by markdown links
700700
*/
701701
function resolveLinkTags(text: string): string {
702-
// Match {@link ApiName} or {@link ApiName description}
702+
// Match {@link ApiName} as well as {@link ApiName | description}
703703
const linkPattern = /\{@link\s+([^}]+)\}/g;
704704

705705
return text.replace(linkPattern, (match, linkContent) => {
706-
const parts = linkContent
707-
.replace("@link", "")
708-
.trim()
709-
.split("|")
710-
.map((p) => p.trim());
706+
// Split on the pipe in case a different link text is specified after.
707+
// This is not standard JSDoc syntax but instead something typedoc picks up
708+
// from TSDoc. See:
709+
// - https://jsdoc.app/tags-inline-link
710+
// - https://typedoc.org/documents/Tags.__link_.html
711+
const parts = linkContent.split("|").map((p) => p.trim());
711712
const apiName = parts[0];
712713
const description = parts[1] || `\`${apiName}\``;
713714

714-
// Look up the API in the lookup tables
715-
let href = repoApiLookup.get(apiName) || typedocLookup.get(apiName)?.href;
715+
// Find a proper href for the @link
716+
let href =
717+
// Prefer exact docs for unstable APIs if they exist (they usually shouldn't)
718+
repoApiLookup.get(apiName) ||
719+
// But normally we don't include the `unstable_` prefix in the filename/URL
720+
repoApiLookup.get(apiName.replace(/^unstable_/, "")) ||
721+
// Fall through to typedocs if a repo doc doesn't exist
722+
typedocLookup.get(apiName)?.href;
716723

717724
if (!href) {
718725
// If not found, return as plain text with a warning

0 commit comments

Comments
 (0)