Skip to content

[lexical-website] Bug Fix: resolve external API links and shorten submodule labels - #9220

Merged
etrepum merged 5 commits into
meta:mainfrom
etrepum:fix/api-external-type-links
Sep 24, 2026
Merged

etrepum merged 5 commits into
meta:mainfrom
etrepum:fix/api-external-type-links

Conversation

@etrepum

@etrepum etrepum commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Description

The API reference emits source URLs pointing into Lexical's node_modules and leaves dependency types unlinked. Those files are not in the repository. The API sidebar also repeats package prefixes in non-React submodule labels, causing unnecessary wrapping.

  • Use TypeDoc documentation mappings for browser/JavaScript types, TypeScript utility types, React (including both JSX element namespaces), Preact signals, mdast/unist, markdown utilities, Yjs, and fast-check. No new dependencies are needed.
  • Fall back to the exact installed package/version/file on UNPKG for other external types and dependency source references. Preserve Lexical's own source links and display dependency paths without the install layout.
  • Preserve #L… anchors on direct app.unpkg.com/.../files/... URLs where UNPKG renders its interactive viewer (up to 50,000 characters and 2,000 lines). Keep file-only links for larger files. For unknown symbols, only use offsets when the filename ends in .d.ts, .d.cts, or .d.mts: TypeDoc resolves declaration-map filenames without remapping their offsets. Mapped-source links remain file-only; "Defined in" links retain their original declaration-file anchors.
  • Strip installation paths from source labels even for private dependencies or missing manifests, which cannot get public source URLs.
  • Add rendering regressions for flat and pnpm installs, declaration/signature anchors, declaration maps, Unicode and CRLF offsets, private/missing manifests, large-file limits, inline links, mapping precedence, and an external Node that must not resolve to the DOM type.
  • Show short submodule names inside every generated package category, including nested groups. Use TypeDoc's exact module titles to preserve spelling and underscores; preserve existing navigation targets, structure, and ordering.

Test plan

Before

Generated API Markdown using the original TypeDoc configuration:

rg -o '\]\([^)]*node_modules[^)]*\)' ../api-before | wc -l
77

The conversion audit also found 131 unresolved dependency symbols.

The updated line-anchor rendering regression failed against the previous implementation. The added declaration-map fixture also reproduces the invalid mapped-source anchors in both flat and pnpm installs:

node node_modules/vitest/vitest.mjs run --project scripts-unit scripts/__tests__/unit/typedocExternalLinks.test.ts
 Test Files  1 failed (1)
      Tests  2 failed (2)

Before the declaration-map guard, the regenerated Yjs type links pointed to Snapshot.js#L1 and Transaction.js#L28, although the classes are on lines 28 and 48 respectively.

The actual Docusaurus sidebar generator also produced redundant labels:

@lexical/compiler: 3 children, 3 labels repeat the package prefix
@lexical/extension: 29 children, 29 labels repeat the package prefix
@lexical/headless: 1 children, 1 labels repeat the package prefix
@lexical/internal: 8 children, 8 labels repeat the package prefix
Labels repeating their package prefix: 41

After

node node_modules/vitest/vitest.mjs run --project scripts-unit scripts/__tests__/unit/typedocExternalLinks.test.ts:

 Test Files  1 passed (1)
      Tests  2 passed (2)

Website TypeScript, targeted ESLint, Prettier and git diff --check pass.

Generated API audit:

136 API pages; 0 node_modules links
93 UNPKG links; 88 line anchors
Yjs mapped-source links: 5; line anchors: 0

The regenerated Yjs links now target [email protected]/files/src/utils/Snapshot.js and [email protected]/files/src/utils/Transaction.js without anchors. The declaration-map fixture confirms mapped-source links omit anchors while "Defined in" links still use mapped.d.ts#L2.

All 78 React JSX references now link to React documentation. Three Preact callback/disposer references now link to its core documentation. The 28 Preact "Defined in" links still point to exact source locations; undocumented types retain source fallbacks.

The earlier HTTP audit confirmed the UNPKG destinations and anchor elements exist, plus all three new Preact documentation anchors. The declaration-map regression and regenerated API audit additionally check that mismatched source-file/declaration-offset pairs do not produce anchors. All 131 previously unresolved dependency symbols have links.

The full website build passed with the line-anchor changes. The subsequent build with the additional mappings completed site compilation and generation but failed at final redirect creation because the reused output directory already contained the redirect. A clean-output rerun was stopped after stalling during bundling; API generation, rendered regression tests, and the link audit all pass. Existing non-fatal TSDoc, third-party bundler and API-index minifier warnings remain.

Sidebar validation invokes the real default and custom Docusaurus generators against the generated document metadata:

@lexical/compiler: 3 children, 0 labels repeat the package prefix
@lexical/extension: 29 children, 0 labels repeat the package prefix
@lexical/headless: 1 children, 0 labels repeat the package prefix
@lexical/internal: 8 children, 0 labels repeat the package prefix
@lexical/react: 60 children, 0 labels repeat the package prefix
Labels repeating their package prefix: 0
All document and category targets preserved

A structural comparison confirms identical sidebar structure, ordering, document IDs, and category links. Website TypeScript, targeted ESLint, Prettier, and git diff --check were rerun successfully for the navigation change. The full site bundle was not rebuilt for this label-only update.

For the declaration-map fix, reran the rendering regressions, generated all 136 API pages, and passed website TypeScript, targeted ESLint, Prettier, and git diff --check. The full website bundle was not rerun for this resolver-only fix.

Validated on Linux; browser and other OS suites were not run for this documentation-only change.

## Description

The API reference emits source URLs pointing into Lexical's `node_modules` and leaves dependency types unlinked. Those files are not in the repository.

- Use TypeDoc documentation mappings for browser/JavaScript types, TypeScript utility types, React, mdast/unist, markdown utilities, Yjs, and fast-check. No new dependencies are needed.
- Fall back to the exact installed package/version/file on UNPKG for other external types and dependency source references. Preserve Lexical's own source links and display dependency paths without the install layout.
- Keep line numbers in source labels but omit UNPKG fragments, since its large-file viewer does not provide line anchors.
- Add rendering regressions for flat and pnpm installs, declaration/signature sources, inline links, mapping precedence, and an external `Node` that must not resolve to the DOM type.

## Test plan

### Before

Generated API Markdown using the original TypeDoc configuration:

```sh
rg -o '\]\([^)]*node_modules[^)]*\)' ../api-before | wc -l
```

```text
77
```

The conversion audit also found 131 unresolved dependency symbols.

### After

Website build (from `packages/lexical-website`): `IGNORE_PEER_DEPENDENCIES=react node node_modules/@docusaurus/core/bin/docusaurus.mjs build`:

```text
[SUCCESS] Generated static files in "build".
```

`node node_modules/vitest/vitest.mjs run --project scripts-unit scripts/__tests__/unit/typedocExternalLinks.test.ts`:

```text
 Test Files  1 passed (1)
      Tests  2 passed (2)
```

Generated-link audit, including HTTP destinations and documentation anchors:

```text
136 API pages; 0 node_modules links
102 distinct external links; 89 destination pages checked
Unverified or broken external targets: []
```

All 131 dependency symbols now resolve. Website TypeScript, targeted ESLint, Prettier, and `git diff --check` pass. The website build emits non-fatal TSDoc, third-party bundler, and API-index minifier warnings. Validated on Linux; browser and other OS suites were not run for this documentation-only change.
…d doc mappings

## Description

UNPKG source fallbacks currently discard working line anchors and omit documentation mappings for React JSX elements and Preact signal types. Dependencies without publishable manifests also retain installation paths in their source labels.

Use direct app.unpkg.com file URLs and preserve source lines for files within UNPKG's interactive viewer limits. Derive symbol lines from TypeDoc's source offsets, and keep file-only links for large files. Add React JSX and Preact signal/callback/disposer documentation mappings, while retaining actual source links for "Defined in". Clean dependency source labels even when no public URL can be generated.

## Test plan

### Before

Run the updated rendering regression against the previous implementation:

```sh
node node_modules/vitest/vitest.mjs run --project scripts-unit scripts/__tests__/unit/typedocExternalLinks.test.ts
```

```text
 Test Files  1 failed (1)
      Tests  2 failed (2)
```

The generated docs contained 78 React JSX source fallbacks.

### After

Run the same rendering regression, including flat/pnpm installs, CRLF and Unicode offsets, declaration/signature lines, both UNPKG viewer limits, and private/missing manifests:

```text
 Test Files  1 passed (1)
      Tests  2 passed (2)
```

Generated API audit:
- 136 pages, zero node_modules URLs.
- All 78 React JSX references link to React documentation.
- Three Preact callback/disposer references now link to documentation; 28 "Defined in" references retain exact source links.
- 93 distinct UNPKG links, including 90 verified line anchors. All remaining destinations were covered by the HTTP/anchor audit.
- Preact documentation anchors verified against their destination page.

Website TypeScript, targeted ESLint, Prettier and git diff --check pass. Validated on Linux; browser and other OS suites were not run for this documentation-only change. The site compilation and generated-link checks completed; rebuilding into the reused output directory failed at final redirect creation because the redirect already existed.
## Description

The API sidebar already groups non-React submodules under their packages, but their labels repeat the full package prefix and wrap unnecessarily. Use TypeDoc's exact module titles to display short submodule names in every generated package category, including nested categories. This applies the existing React navigation convention to extension, compiler, headless, internal, and other packages without package-specific rules.

## Test plan

### Before

Run the sidebar probe against the website's actual sidebarItemsGenerator and Docusaurus DefaultSidebarItemsGenerator using the generated document metadata:

```sh
node ../check-api-sidebar.mjs
```

```text
@lexical/compiler: 3 children, 3 labels repeat the package prefix
@lexical/extension: 29 children, 29 labels repeat the package prefix
@lexical/headless: 1 children, 1 labels repeat the package prefix
@lexical/internal: 8 children, 8 labels repeat the package prefix
@lexical/react: 60 children, 0 labels repeat the package prefix
Labels repeating their package prefix: 41
```

### After

```sh
EXPECT_SHORT=1 SIDEBAR_OUT=../api-sidebar-after.json node ../check-api-sidebar.mjs
```

```text
@lexical/compiler: 3 children, 0 labels repeat the package prefix
@lexical/extension: 29 children, 0 labels repeat the package prefix
@lexical/headless: 1 children, 0 labels repeat the package prefix
@lexical/internal: 8 children, 0 labels repeat the package prefix
@lexical/react: 60 children, 0 labels repeat the package prefix
Labels repeating their package prefix: 0
All document and category targets preserved
```

A structural comparison confirms identical sidebar structure, ordering, document IDs, and category links. Website TypeScript, targeted ESLint, Prettier, and git diff --check pass. Validated on Linux; browser and other OS suites were not run for this navigation-label change. The full site bundle was not rebuilt; validation invokes the actual sidebar generators directly.
…y sources

## Description

TypeDoc resolves declaration maps for unknown-symbol filenames without remapping their declaration-file offsets. Using those offsets in the mapped source produces incorrect UNPKG line anchors, including Yjs Snapshot and Transaction.

Only derive unknown-symbol anchors when the filename matches /\.d\.[cm]?ts$/. Keep mapped-source links at the file level and preserve SourcePlugin's declaration-file anchors. Add a declaration-map rendering fixture for flat and pnpm installs that verifies both behaviors.

## Test plan

### Before

With the declaration-map fixture added before the resolver fix:

```sh
node node_modules/vitest/vitest.mjs run --project scripts-unit scripts/__tests__/unit/typedocExternalLinks.test.ts
```

```text
 Test Files  1 failed (1)
      Tests  2 failed (2)
```

### After

The same command passes:

```text
 Test Files  1 passed (1)
      Tests  2 passed (2)
```

Regenerated the API Markdown using the website's TypeDoc configuration and checked the resulting URLs:

```text
YJS: `Snapshot` https://app.unpkg.com/[email protected]/files/src/utils/Snapshot.js
YJS: `Transaction` https://app.unpkg.com/[email protected]/files/src/utils/Transaction.js
Yjs mapped-source links: 5; line anchors: 0
UNPKG links: 93; line anchors: 88
node_modules links: 0
```

Website TypeScript, targeted ESLint, Prettier, and git diff --check pass. Validated on Linux; the full website bundle, browser tests, and other operating systems were not rerun for this resolver-only change.
@vercel

vercel Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
lexical Ready Ready Preview Sep 24, 2026 4:06pm UTC
lexical-playground Ready Ready Preview Sep 24, 2026 4:06pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 24, 2026
@etrepum etrepum added extended-tests Run extended e2e tests on a PR CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. and removed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Sep 24, 2026
@etrepum
etrepum marked this pull request as ready for review September 24, 2026 16:58
@etrepum
etrepum added this pull request to the merge queue Sep 24, 2026
Merged via the queue into meta:main with commit f0f9d35 Sep 24, 2026
83 checks passed
@etrepum etrepum mentioned this pull request Sep 28, 2026

This branch was successfully deployed

2 active deployments
Preview – lexical — 4580cc55 Deployed Sep 24, 2026 by vercel[bot]
Preview – lexical-playground — 4580cc55 Deployed Sep 24, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants