Skip to content

docs(useOutlineFromMarkdown): add hook docs and a docs article example block - #9719

Merged
cixzhang merged 1 commit into
meta:mainfrom
hskl18:docs/9572-use-outline-from-markdown
Nov 3, 2026
Merged

cixzhang merged 1 commit into
meta:mainfrom
hskl18:docs/9572-use-outline-from-markdown

Conversation

@hskl18

@hskl18 hskl18 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Reader impact

A builder cannot find useOutlineFromMarkdown: astryx hook useOutlineFromMarkdown answers No hook named "useOutlineFromMarkdown", and the hook has no docsite page or runnable example. After this change the hook has a page at /components/useOutlineFromMarkdown, astryx hook and astryx search return it, and astryx template useOutlineFromMarkdownHookUsage <path> copies the example.

Source of truth

  • useOutlineFromMarkdown.ts, parseOutlineFromMarkdown.ts and module:Outline/parseOutlineFromMarkdown.
  • component:Outline FR4, for the block's offset.
  • architecture:knowledge-contracts INV28.

Correction

Adds a HookDoc next to the source, and blocks/components/Outline/useOutlineFromMarkdownHookUsage (exampleFor: 'useOutlineFromMarkdown'). One useState holds a Markdown string. Markdown renders it, useOutlineFromMarkdown gives the Outline its items, and "Add section" appends a heading to the string. The hook's source file adds the doc to its SYNC list.

Choices you may want to check:

  • The block passes only markdown. id, label and level are all on screen, through the links, the text and the indent. options is in the HookDoc. docs(useCollator): add a locale-aware name sort example block #9510 calls useCollator() the same way, though docs(useListFocus): add a recent files example block #9577 passes its defaults. createMarkdownHeadingLinks would show plugins, but it adds a copy control to every heading, against the issue's "no unrelated UI".
  • Outline gets offset={8}, although its prop doc says to leave it at 0 when nothing overlays the content. The docs page mounts the block inline, and FR4 scrolls every ancestor at 0. In Chromium at 0, a click moved the docs page from 1572 to 1882 and left the block's top under the site header. A comment in the block gives the reason.
  • The article sits in a ScrollableArea so a link has somewhere to scroll. Its ref goes to scrollContainerRef, so the highlight follows the article.
  • Repeated presses add another "New section". The ids stay unique (new-section, new-section-1).

Review of the doc turned up two cases where the hook's ids differ from Markdown's. A test run confirmed both. The doc states them, and this PR leaves the behavior as it is:

  • # Intro [ref] with sources={{ref: {...}}}: Markdown renders id="intro", the hook returns intro-ref. The hook has no way to receive sources. Without sources both give intro-ref.
  • # Intro [pending with isStreaming: Markdown ends on intro, the hook with isFinal: false returns intro-pending.

One question: module:Outline/parseOutlineFromMarkdown FR1 says both utilities take the same parser options as Markdown, so is the sources case a gap you want tracked in its own issue?

Evidence

Headless Chromium against the docsite dev server, /components/useOutlineFromMarkdown, 1440 x 1000:

  • The block renders under Examples with five entries, and ### entries are indented. Each entry's id is held by one element on the page, inside the article.
  • Clicking "Rebuild the project" scrolls the article from 0 to 88 and marks that entry current. The docs page stays at the same scroll position.
  • Scrolling the article back to its top moves the highlight back to the first entry.
  • "Add section" adds an entry that links to the new heading, and a click on it scrolls there and marks it current. A second press adds #new-section-1. The first run, on a cold dev server that was still compiling, showed the new entry not current and no second entry. Two warm reruns showed both. I did not isolate the difference.
  • At 390 px there is no horizontal page scroll. The article column is 123 px wide, which is readable but cramped. The issue does not ask for a phone layout, so the block stays minimal.
  • The console logs one Encountered a script tag error on this page and on /components/useClipboard.

packages/cli/api/template/use-outline-from-markdown-hook-usage.test.tsx checks that each entry links to a rendered heading and that the button adds a linked entry. With the hook call replaced by an empty array, both tests fail.

The coverage report no longer lists this hook under either gap. On this head it counts 44 hooks without a doc and 67 without a block.

Scope

  • This PR changes documentation only, or names every necessary generated artifact. The generated artifact is the new doc's and block's routes in internal/shadcn-registry/routes.lock.json, from UPDATE_SHADCN_ROUTE_LOCK=1 node apps/docsite/scripts/generate-data.mjs. apps/sandbox/scripts/next-export-routes.json, the checked list, gains the block's route.
  • Runtime, API, visual, and policy changes were removed or split. No behavior change.
  • Public text and artifacts contain no internal Meta context.

Testing

On this head, macOS, Node 24.22.2 (.nvmrc pins 24.22.1):

  • pnpm lint:strict: 0 errors, 166 warnings, none in these files. prettier --check on the touched source files: clean.
  • pnpm build, pnpm -F @astryxdesign/docsite build, pnpm -F @astryxdesign/cli typecheck, node apps/docsite/scripts/generate-data.mjs (no route lock difference): pass.
  • pnpm check:changesets, changeset-coverage pr, check-knowledge, sync-exports --check, verify-exports, generate-cli-readme --check: pass. The changeset is @astryxdesign/core and @astryxdesign/cli patch, [docs].
  • vitest run --project node on the new test and apps/sandbox/src/route-manifest.test.ts: 8 passed. On packages/cli/foundation/discovery, packages/cli/api/template, packages/cli/assets/templates and internal/shadcn-registry: 1177 passed. On the tree.test.mjs files in packages/cli/api/build, packages/cli/api/search and packages/cli/foundation/doc-compiler: 35 passed.
  • vitest run --project ui packages/core/src/Outline: 64 passed. apps/docsite data-extraction and example-coverage: 135 passed.

Before the rebases and the doc's final wording, pnpm typecheck passed and pnpm test gave 34856 passed and 49 failed in 14 files, none of which this PR touches. On a clean base, those files gave 48 of the 49 failures. The other is a 30 s timeout in doctor-integration.test.mjs, which passes alone on this branch. Sampled logs show errors such as bash 3.2's OBS_ARGS[@]: unbound variable and cp --reflink, which point to macOS. No Linux run confirms that, and not all 48 were traced. The full suite was not rerun after the rebases. The last one resolved a conflict in the two route lists, and the rest of the diff did not change.

Not run: pnpm test:build past its packed-consumer test (2 passed), because theme-layer-cascade.js needs Chromium 1228, which is not installed here. Left to hosted CI, so unverified until it runs: test:ui:isolated, test:docsite-browser, registry verification, and the a11y, visual, RTL and interaction lanes. WebKit, Firefox, dark theme and touch were not checked. The browser checks above used Chromium 1248 from a local cache.

Hosted CI has not run. A draft runs no CI, and once this is marked ready the required checks fail with "Waiting for a maintainer's ci:run label" until a maintainer adds it.

I used Claude Code to write the doc, the block, the test and this description, and to run the checks above. Separate Claude Code sessions checked the plan and this description, and Codex reviewed the plan and the change.

Reviewed with sol loop: 2 rounds with GPT-6.1 Sol (xhigh). Sol verdict: approved. It found the two id differences above, which the doc now states.

Fixes #9572

@vercel

vercel Bot commented Nov 3, 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 3, 2026 8:28am UTC

Request Review

@meta-cla

meta-cla Bot commented Nov 3, 2026

Copy link
Copy Markdown

Hi @hskl18!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge needs:design-review Affects visuals — Design should review labels Nov 3, 2026
@astracat-bot

astracat-bot Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 3, 2026, 8:41 AM UTC

…e block

useOutlineFromMarkdown is public but had no hook doc and no example, so
astryx hook denied it exists and it had no docsite page. The doc lists its
params and return, and says where its ids can differ from Markdown's: with
sources, and while content streams. The block builds an article and an Outline
from one Markdown string through the hook. A button adds a section and its
linked entry.

Fixes meta#9572
@hskl18
hskl18 force-pushed the docs/9572-use-outline-from-markdown branch from 22365e3 to 863cb52 Compare November 3, 2026 08:20
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 3, 2026
@hskl18
hskl18 marked this pull request as ready for review November 3, 2026 08:22

@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.

This looks ready to merge. The hook doc and the useOutlineFromMarkdown — Docs Article block close the hook's docs gap, and the block meets each criterion for a public hook's example.

  • astryx hook useOutlineFromMarkdown and astryx search now return the hook. The block's outline entries link to the rendered headings, and both new tests fail when the hook call is removed.
  • The doc's note that a heading citing a sources entry gets a different id is accurate. Whether to track that gap in its own issue is a maintainer decision, and it does not block this pull request.

[Automated review]

@cixzhang cixzhang added the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Nov 3, 2026
@cixzhang cixzhang closed this Nov 3, 2026
@cixzhang cixzhang reopened this Nov 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 863cb52

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
Outline · Storybook 24.2 kB (0) · 4.2 kB CSS (0) 1,233 (0) ✓ · ✓ · ✓

Package size: measured; main has no measurement of the merge base to compare yet.

Touched components checked; add ci:run-visual, ci:run-a11y or ci:run-rtl to run the full suites.


Generated by PR Enrichment workflow | View full report

@github-actions github-actions Bot removed the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Nov 3, 2026
@cixzhang
cixzhang merged commit 1208475 into meta:main Nov 3, 2026
66 checks passed
@hskl18
hskl18 deleted the docs/9572-use-outline-from-markdown branch November 13, 2026 23:53

This branch was successfully deployed

1 active deployment
Preview — 863cb52b Deployed Nov 3, 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. community Authored by a community contributor (not on the eng/design team) needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docs(useOutlineFromMarkdown): add hook docs and a minimal live example

2 participants