Skip to content

fix(cli): a namespace section read loads the project once, not once per guide below it - #8504

Merged
cixzhang merged 3 commits into
meta:mainfrom
vjeux:uikit/docs-namespace-one-load
Nov 4, 2026
Merged

cixzhang merged 3 commits into
meta:mainfrom
vjeux:uikit/docs-namespace-one-load

Conversation

@vjeux

@vjeux vjeux commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

User impact

A section read on a docs namespace, such as astryx docs authoring <section>, takes most of a second: it loads the project once per guide below the namespace. The same cost makes docs-homes.test.mjs time out at its 60 s limit in a loaded full CLI run.

Problem and solution fit

  • namespaceSection read each guide with resolveTopicDocs(guide.route), and each of those calls loaded the docs catalog again (Project.load, then project.docs()).
  • A fresh catalog also misses the per-catalog lowering memo, so every guide was lowered again as well.
  • authoring has 49 guides below it, so one section read there loaded the project 50 times. docs-homes.test.mjs reads all 19 field-reference sections through authoring, so that case took about 19 s on its own.

Expected behavior and authority

spec:AST-046 FR6: a namespace answers a section read from the one guide below it that has the section; that answer is unchanged. #7212 introduced these reads; the cost grew when #7835 moved the integration guides under authoring.

Smallest restoration

The namespace read already holds the catalog it loaded, because resolveDocsArgument returns it. namespaceSection now takes that catalog and reads every guide from it; resolveDocsArgument and resolveTopicDocs accept an optional catalog. No output, API or test limit changes.

Evidence

  • Reproduction before the change: a new case in namespace-section.test.mjs spies on Project.load during docs('authoring', <section>) and counts 50 calls on main.
  • Result after the change: the same case counts 1 call. Same machine and load:
    • the docs-homes case "keeps everything for integration authors under authoring…" takes 19.2 s and 19.3 s on main, and 1.5 s and 2.4 s with the fix;
    • nineteen docs('authoring', key) reads take 6.9 s on main and 0.48 s with the fix (slowest read: 706 ms on main, 36 ms with the fix).
  • Representative unchanged path: the existing namespace-section cases still compare each namespace section read with the guide's own section read (toEqual), in English, dense and Chinese.
  • Regression test: the Project.load count above fails as soon as a guide loads the project again.

Scope

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

Testing

  • packages/cli/api/docs: 167 of 167 tests pass.
  • Full packages/cli suite: 9,547 tests pass and 1 fails, a 30 s timeout in api/search/_main-searcher.test.mjs at load 19. Run alone, it passes twice (6 of 6), and this change doesn't touch search.
  • Root build, typecheck, CI=true pnpm lint (0 errors), check:repo and check:changesets pass.

…er guide below it

astryx docs <namespace> <section> read every guide below the namespace with resolveTopicDocs(guide.route), and each call loaded the project's docs catalog again, which also missed the per-catalog lowering memo. The namespace read already holds the catalog it loaded, so namespaceSection now reads every guide from it: resolveDocsArgument and resolveTopicDocs take an optional catalog. authoring has 49 guides below it, so a section read there loaded the project 50 times and now loads it once; docs-homes.test.mjs reads 19 sections through authoring and drops from about 19 s to about 2 s.
@vercel

vercel Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 4, 2026 4:46pm UTC

Request Review

@astracat-bot

astracat-bot Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 4, 2026, 5:00 PM UTC

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 4f4c950

Storybook · Sandbox · built from this PR's head

Package size: @astryxdesign/cli 3.35 MB packed (+556 B); no new dependencies.

API changes: none in this pull request

Committed API report behind this build: cli 8 rows, core 2 rows; run pnpm api:report.

Not run on this PR: add ci:run-visual, ci:run-a11y or ci:run-rtl to run them.


Generated by PR Enrichment workflow | View full report

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 26, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks — reading every guide from the catalog the namespace read already loaded is a clean fix, and every namespace section answer stays the same, but one change is needed before this can merge. Because the catalog travels in the same options object the public docs() receives (packages/cli/api/docs/docs.mjs:152), callers can now set an undeclared catalog option: a builtins catalog hides a project's integration docs, and a value such as 'npm' throws a raw TypeError and then ends the process through an unhandled rejection. Please pass the loaded catalog as its own internal argument (for example resolveTopicDocs(guide.route, options, catalog)) and add a case showing docs() ignores a catalog key, since spec:AST-017 FR14 allows no undocumented caller-settable control. Optionally, the changeset's "tens of milliseconds" describes the in-process read better than the whole astryx docs authoring <section> command.

[Automated review]

Comment thread packages/cli/api/docs/_adapter.mjs Outdated
*/
export async function resolveDocsArgument(topic, {cwd} = {}) {
const catalog = await loadDocsCatalog(cwd);
export async function resolveDocsArgument(topic, {cwd, catalog: loaded} = {}) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This reads catalog from the same options object the public docs() forwards (docs.mjs:152), so docs(topic, section, {catalog}) now skips the project load and reads whatever the caller passes: a builtins catalog hides the project's integration docs, and {catalog: 'npm'} throws a raw TypeError and then ends the process through an unhandled rejection in buildProjectTree. Taking the catalog as a separate internal argument, for example resolveDocsArgument(topic, {cwd} = {}, loaded), keeps it out of reach of public callers (spec:AST-017 FR14).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This keeps the catalog out of every caller's reach: resolveDocsArgument(topic, {cwd} = {}, loaded) and resolveTopicDocs(topic, options = {}, loaded) now take the loaded catalog as a separate internal argument (afcaf2b). A new case in namespace-section.test.mjs passes {catalog: 'npm'} to docs() for a namespace section and a flat topic and gets the same answers as without it; on the previous head it threw the TypeError you described.

'@astryxdesign/cli': patch
---

[fix] `astryx docs <namespace> <section>` loads the project once instead of once for every guide below the namespace, so a section read on a namespace with many guides, such as `astryx docs authoring <section>`, answers in tens of milliseconds instead of most of a second. The answer is unchanged.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The read itself does drop to tens of milliseconds, but the whole astryx docs authoring <section> command still measured about 0.6 s end to end because start-up dominates; wording such as "the read itself takes tens of milliseconds instead of hundreds" would match what users see.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The changeset now says what users see: "the read itself takes tens of milliseconds instead of hundreds" (afcaf2b).

…option

resolveDocsArgument and resolveTopicDocs take the catalog a read already loaded as a separate third argument instead of an options field, so a caller of the public docs() cannot set it: a catalog key in docs() options is ignored and the read loads its own project (spec:AST-017 FR14). The changeset says the read itself, not the whole command, drops to tens of milliseconds.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No further changes are needed: reading every guide from the catalog the namespace read already loaded makes astryx docs authoring <section> load the project once instead of 50 times, and every namespace section answer stays the same in English, dense and Chinese. The requested follow-up is in place, since the loaded catalog now travels as an internal argument and docs() ignores a catalog option exactly as before, which the new test pins.

[Automated review]

@vjeux
vjeux marked this pull request as draft October 29, 2026 22:36
@vjeux
vjeux marked this pull request as ready for review November 4, 2026 14:28
@cixzhang cixzhang added the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Nov 4, 2026
@cixzhang
cixzhang marked this pull request as draft November 4, 2026 14:40
@cixzhang
cixzhang marked this pull request as ready for review November 4, 2026 14:40
@cixzhang
cixzhang marked this pull request as draft November 4, 2026 16:35
@cixzhang
cixzhang marked this pull request as ready for review November 4, 2026 16:35

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved: reading every guide from the catalog the namespace read already loaded makes astryx docs authoring <section> load the project once instead of 50 times, and every namespace section answer stays the same in English, dense and Chinese.

The new load-count test fails without the fix and passes with it, and nothing else is needed from you.

[Automated review]

@cixzhang
cixzhang merged commit 048476f into meta:main Nov 4, 2026
69 of 106 checks passed
@vjeux
vjeux deleted the uikit/docs-namespace-one-load branch November 4, 2026 20:56

This branch was successfully deployed

1 active deployment
Preview — 4f4c9504 Deployed Nov 4, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants