Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/generators/jsx-ast/generate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ const remarkRecma = getRemarkRecma();
*
* @type {import('./types').Generator['processChunk']}
*/
export async function processChunk(slicedInput, itemIndices, docPages) {
export async function processChunk(
slicedInput,
itemIndices,
{ docPages, stabilityOverviewEntries }
) {
const results = [];

for (const idx of itemIndices) {
Expand All @@ -28,7 +32,8 @@ export async function processChunk(slicedInput, itemIndices, docPages) {
entries,
head,
sideBarProps,
remarkRecma
remarkRecma,
stabilityOverviewEntries
);

results.push(content);
Expand All @@ -54,14 +59,30 @@ export async function* generate(input, worker) {
? config.index.map(({ section, api }) => [section, `${api}.html`])
: headNodes.map(node => [node.heading.data.name, `${node.api}.html`]);

// Pre-compute stability overview data once — avoid serialising full AST nodes to workers
const stabilityOverviewEntries = headNodes
.filter(node => node.stability?.children?.length)
.map(({ api, heading, stability }) => {
const [{ data }] = stability.children;
return {
api,
name: heading.data.name,
stabilityIndex: parseInt(data.index, 10),
stabilityDescription: data.description.split('. ')[0],
};
});

// Create sliced input: each item contains head + its module's entries
// This avoids sending all 4700+ entries to every worker
const entries = headNodes.map(head => ({
head,
entries: groupedModules.get(head.api),
}));

for await (const chunkResult of worker.stream(entries, entries, docPages)) {
for await (const chunkResult of worker.stream(entries, entries, {
docPages,
stabilityOverviewEntries,
})) {
yield chunkResult;
}
}
32 changes: 27 additions & 5 deletions src/generators/jsx-ast/utils/buildContent.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export const transformHeadingNode = async (
* @param {ApiDocMetadataEntry} entry - The API metadata entry to process
* @param {import('unified').Processor} remark - The remark processor
*/
export const processEntry = (entry, remark) => {
export const processEntry = (entry, remark, stabilityOverviewEntries = []) => {
// Deep copy content to avoid mutations on original
const content = structuredClone(entry.content);

Expand All @@ -272,6 +272,18 @@ export const processEntry = (entry, remark) => {
(node, idx, parent) => (parent.children[idx] = createPropertyTable(node))
);

// Inject the stability overview table where the slot tag is present
if (
stabilityOverviewEntries.length &&
entry.tags.includes('STABILITY_OVERVIEW_SLOT_BEGIN')
) {
content.children.push(
createJSXElement(JSX_IMPORTS.StabilityOverview.name, {
entries: stabilityOverviewEntries,
})
);
Comment on lines +280 to +284
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

processEntry() appends the <StabilityOverview /> element to content.children, which places the table at the end of the section. In the legacy HTML generator the stability overview is injected near the top of the target section (via buildExtraContent, before the rest of the nodes), so this likely changes the intended placement of the slot. Consider inserting the overview at a deterministic position (e.g., right after the section heading / before the main body), or otherwise aligning placement with the slot semantics used in legacy-html.

Suggested change
content.children.push(
createJSXElement(JSX_IMPORTS.StabilityOverview.name, {
entries: stabilityOverviewEntries,
})
);
const stabilityOverviewElement = createJSXElement(
JSX_IMPORTS.StabilityOverview.name,
{ entries: stabilityOverviewEntries }
);
// Insert stability overview near the top of the section, preferably right
// after the first heading node to align with legacy HTML placement.
if (Array.isArray(content.children) && content.children.length > 0) {
const headingIndex = content.children.findIndex(
node => node && node.type === 'heading'
);
const insertIndex = headingIndex >= 0 ? headingIndex + 1 : 0;
content.children.splice(insertIndex, 0, stabilityOverviewElement);
} else {
content.children = [stabilityOverviewElement];
}

Copilot uses AI. Check for mistakes.
}
Comment on lines +275 to +285
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New stability-overview injection logic isn’t covered by unit tests. This file already has a test suite (utils/__tests__/buildContent.test.mjs), so adding a focused test that verifies the StabilityOverview element is included/excluded based on entry.tags would help prevent regressions.

Copilot uses AI. Check for mistakes.

return content;
};

Expand All @@ -286,7 +298,8 @@ export const createDocumentLayout = (
entries,
sideBarProps,
metaBarProps,
remark
remark,
stabilityOverviewEntries = []
) =>
createTree('root', [
createJSXElement(JSX_IMPORTS.NavBar.name),
Expand All @@ -302,7 +315,9 @@ export const createDocumentLayout = (
createElement('br'),
createElement(
'main',
entries.map(entry => processEntry(entry, remark))
entries.map(entry =>
processEntry(entry, remark, stabilityOverviewEntries)
)
),
]),
createJSXElement(JSX_IMPORTS.MetaBar.name, metaBarProps),
Expand All @@ -321,7 +336,13 @@ export const createDocumentLayout = (
* @param {import('unified').Processor} remark - Remark processor instance for markdown processing
* @returns {Promise<JSXContent>}
*/
const buildContent = async (metadataEntries, head, sideBarProps, remark) => {
const buildContent = async (
metadataEntries,
head,
sideBarProps,
remark,
stabilityOverviewEntries = []
) => {
// Build props for the MetaBar from head and entries
const metaBarProps = buildMetaBarProps(head, metadataEntries);

Expand All @@ -330,7 +351,8 @@ const buildContent = async (metadataEntries, head, sideBarProps, remark) => {
metadataEntries,
sideBarProps,
metaBarProps,
remark
remark,
stabilityOverviewEntries
);

// Run remark processor to transform AST (parse markdown, plugins, etc.)
Expand Down
4 changes: 4 additions & 0 deletions src/generators/web/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ export const JSX_IMPORTS = {
name: 'ArrowUpRightIcon',
source: '@heroicons/react/24/solid/ArrowUpRightIcon',
},
StabilityOverview: {
name: 'StabilityOverview',
source: resolve(ROOT, './ui/components/StabilityOverview'),
},
};

/**
Expand Down
4 changes: 3 additions & 1 deletion src/generators/web/generate.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import { readFile, writeFile } from 'node:fs/promises';
import { mkdir, readFile, writeFile } from 'node:fs/promises';
import { createRequire } from 'node:module';
import { join } from 'node:path';

Expand Down Expand Up @@ -35,6 +35,8 @@ export async function generate(input) {

// Process all entries together (required for code-split bundles)
if (config.output) {
await mkdir(config.output, { recursive: true });

Comment on lines +38 to +39
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated, and this type of change was blocked previously

// Write HTML files
for (const { html, api } of results) {
await writeFile(join(config.output, `${api}.html`), html, 'utf-8');
Expand Down
56 changes: 56 additions & 0 deletions src/generators/web/ui/components/StabilityOverview/index.jsx
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than adding a new JSX component, which requires serializing and passing more data to the client, can't we just generate the AST in a new file, similarly to how was done with the property table (before it was replaced)?

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import Badge from '@node-core/ui-components/Common/Badge';

import styles from './index.module.css';

const STABILITY_KINDS = ['error', 'warning', 'success', 'info'];
const STABILITY_TOOLTIPS = ['Deprecated', 'Experimental', 'Stable', 'Legacy'];

/**
* @typedef StabilityOverviewEntry
* @property {string} api - The API identifier (basename, e.g. "fs")
* @property {string} name - The human-readable display name of the API module
* @property {number} stabilityIndex - The stability level index (0–3)
* @property {string} stabilityDescription - First sentence of the stability description
*/

/**
* Renders a table summarising the stability level of each API module.
*
* @param {{ entries: Array<StabilityOverviewEntry> }} props
*/
export default ({ entries = [] }) => {
if (!entries.length) {
return null;
}

return (
<table className={styles.table}>
<thead>
<tr>
<th>API</th>
<th>Stability</th>
</tr>
</thead>
<tbody>
{entries.map(({ api, name, stabilityIndex, stabilityDescription }) => (
<tr key={api}>
<td>
<a href={`${api}.html`}>{name}</a>
</td>
<td className={styles.stabilityCell}>
<Badge
kind={STABILITY_KINDS[stabilityIndex]}
data-tooltip={STABILITY_TOOLTIPS[stabilityIndex]}
aria-label={`Stability: ${STABILITY_TOOLTIPS[stabilityIndex]}`}
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stability badge is given a tooltip via data-tooltip, but it isn’t keyboard-focusable here. Other UI (e.g. MetaBar’s stability badge) sets tabIndex={0} so keyboard users can focus the badge and discover the tooltip. Consider adding tabIndex={0} (and, if applicable, matching the conditional aria-label pattern used elsewhere) to keep tooltip behavior accessible.

Suggested change
aria-label={`Stability: ${STABILITY_TOOLTIPS[stabilityIndex]}`}
aria-label={`Stability: ${STABILITY_TOOLTIPS[stabilityIndex]}`}
tabIndex={0}

Copilot uses AI. Check for mistakes.
>
{stabilityIndex}
</Badge>

{` ${stabilityDescription}`}
</td>
</tr>
))}
</tbody>
</table>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.table {
width: 100%;
}

.stabilityCell {
display: flex;
align-items: center;
gap: 0.4rem;
flex-wrap: wrap;
}
Loading