Skip to content

Commit f0e25a7

Browse files
committed
fix(legacy-html): copy its input on the main thread
Building a page splices the heading out of its entries' content and replaces the stability nodes, and on the main thread those entries are the metadata other generators read. With one thread, building `legacy-html` with other targets crashed (`Cannot read properties of undefined (reading 'tagName')`), on `main` too. It now works on a copy there, as it already does in a worker. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent dee4af9 commit f0e25a7

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎.changeset/keep-memory-down.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
'@doc-kit/core': patch
33
'@doc-kit/generator-react': patch
4+
'@node-core/doc-kit-legacy': patch
45
---
56

6-
Builds use less memory, most of all with few threads: each worker's young generation is limited to 96MB, a single thread processes one chunk at a time and lets go of the pages' code before rendering them, and Vite's native bundler gets as many threads as doc-kit and returns the memory it frees. On the Node.js API docs, `--threads 1` now builds with Node.js's `--max-old-space-size=512`.
7+
Builds use less memory, most of all with few threads: each worker's young generation is limited to 96MB, a single thread processes one chunk at a time and lets go of the pages' code before rendering them, and Vite's native bundler gets as many threads as doc-kit and returns the memory it frees. On the Node.js API docs, `--threads 1` now builds with Node.js's `--max-old-space-size=512`, and no longer crashes when `legacy-html` is built alongside other targets.

‎packages/node-legacy/src/legacy-html/generate.mjs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { readFile, cp } from 'node:fs/promises';
44
import { basename, join } from 'node:path';
5+
import { isMainThread } from 'node:worker_threads';
56

67
import getConfig from '@doc-kit/core/utils/configuration/index.mjs';
78
import { writeFile } from '@doc-kit/core/utils/file.mjs';
@@ -33,7 +34,11 @@ export async function processChunk(slicedInput, itemIndices, navigation) {
3334
const results = [];
3435

3536
for (const idx of itemIndices) {
36-
const { head, nodes, headNodes } = slicedInput[idx];
37+
// Building the content changes the entries. A worker has its own copy, but
38+
// on the main thread they're the metadata other generators read too
39+
const { head, nodes, headNodes } = isMainThread
40+
? structuredClone(slicedInput[idx])
41+
: slicedInput[idx];
3742

3843
const nav = navigation.replace(
3944
`class="nav-${head.api}"`,

0 commit comments

Comments
 (0)