Skip to content

[docs-infra] Add a headless source API - #1783

Draft
brijeshb42 wants to merge 1 commit into
di-migration-collapse-resetfrom
di-migration-headless-source
Draft

[docs-infra] Add a headless source API#1783
brijeshb42 wants to merge 1 commit into
di-migration-collapse-resetfrom
di-migration-headless-source

Conversation

@brijeshb42

Copy link
Copy Markdown
Contributor

Ninth in the docs-infra migration stack, on top of #1782.

A host with its own editor — Material UI's DemoEditor, with its styling, focus hint, and error overlay — had no way to drive a docs-infra block: editing meant adopting docs-infra's editor DOM.

editorMode: 'headless' mounts no editor. The rendered file stays highlighted, read-only source, and useCode returns what a host needs to edit it:

  • selectedFileSource — plain text, decoded from whichever shape the source arrived in (string, HAST, serialized HAST, or a compressed payload decoded through the block's fallback dictionary). null in 'internal' mode, where nothing reads it and a hastCompressed payload would pay an inflate for it.
  • selectedFileProjection — the slice a collapsed view is edited through.
  • selectedFileLanguage, selectedFileOriginalName — the grammar and the canonical, pre-transform name.
  • selectedFileEditable, activateEditing() — whether an edit is accepted now, and a way to warm the edit-time engine on focus.

Edits go back through the same setSource the internal editor uses, so the controller, the reset behaviour, and the rendered preview are unchanged.

useFileNavigation also resolves the selected file's projection and forwards it to <Pre>. The precompute has produced one since #1781, but nothing carried it to the editor.

Gate: 4 new browser tests across chromium, firefox, and webkit — a host textarea edits through the headless API and the rendered preview follows, and the internal editor mounts in 'internal' mode but not in 'headless' — plus 5,569 unit tests, a clean typecheck, lint, and docs:validate.

@brijeshb42 brijeshb42 added the scope: docs-infra Involves the docs-infra product (https://www.notion.so/mui-org/b9f676062eb94747b6768209f7751305). label Aug 14, 2026
@code-infra-dashboard

code-infra-dashboard Bot commented Aug 14, 2026

Copy link
Copy Markdown

Deploy preview

Bundle size

Total Size Change: 🔺+2.09KB(+0.06%) - Total Gzip Change: 🔺+473B(+0.05%)
Files: 71 total (0 added, 0 removed, 2 changed)

Show details for 71 more bundles

@mui/internal-docs-infra/useCodeparsed: 🔺+1.1KB(+1.01%) gzip: 🔺+260B(+0.72%)
@mui/internal-docs-infra/useDemoparsed: 🔺+988B(+0.77%) gzip: 🔺+213B(+0.50%)
@mui/internal-docs-infra/abstractCreateDemoparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/abstractCreateDemoClientparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/abstractCreateStreamparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/abstractCreateTypesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/ChunkProviderparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/cliparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeControllerContextparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeExternalsContextparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeHighlighterparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeHighlighter/errorsparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeHighlighter/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeProviderparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CoordinatedLazyparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CoordinatedLazy/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/createDemoDataparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/createDemoData/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/createSitemapparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/createSitemap/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useCodeWindowparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useCoordinatedparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useCopierparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useCrossTabStateparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useDemoControllerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useErrorsparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useLocalStorageStateparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/usePreferenceparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useScrollAnchorparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useSearchparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useSearch/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useStreamparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useStream/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useTypeparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useTypesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useUrlHashStateparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/withDocsInfraparsed: 0B(0.00%) gzip: 0B(0.00%)
addLineGuttersparsed: 0B(0.00%) gzip: 0B(0.00%)
BuildEngineparsed: 0B(0.00%) gzip: 0B(0.00%)
CodeContextparsed: 0B(0.00%) gzip: 0B(0.00%)
CodeEditorparsed: 0B(0.00%) gzip: 0B(0.00%)
CodeHighlighterChunkparsed: 0B(0.00%) gzip: 0B(0.00%)
CodeHighlighterClientparsed: 0B(0.00%) gzip: 0B(0.00%)
CodeInitialSourceLoaderparsed: 0B(0.00%) gzip: 0B(0.00%)
CodeSourceLoaderparsed: 0B(0.00%) gzip: 0B(0.00%)
compileCssWithPostcssparsed: 0B(0.00%) gzip: 0B(0.00%)
createFrameparsed: 0B(0.00%) gzip: 0B(0.00%)
createParseSourceWorkerClientparsed: 0B(0.00%) gzip: 0B(0.00%)
EditingEngineparsed: 0B(0.00%) gzip: 0B(0.00%)
embedTransformsparsed: 0B(0.00%) gzip: 0B(0.00%)
enhanceCodeEmphasisparsed: 0B(0.00%) gzip: 0B(0.00%)
findExpandingRangesparsed: 0B(0.00%) gzip: 0B(0.00%)
getHastTextContentparsed: 0B(0.00%) gzip: 0B(0.00%)
grammarLoadersparsed: 0B(0.00%) gzip: 0B(0.00%)
grammarsparsed: 0B(0.00%) gzip: 0B(0.00%)
isFrameSpanparsed: 0B(0.00%) gzip: 0B(0.00%)
loadIsomorphicCodeVariantparsed: 0B(0.00%) gzip: 0B(0.00%)
parseSourceparsed: 0B(0.00%) gzip: 0B(0.00%)
rolldown-runtimeparsed: 0B(0.00%) gzip: 0B(0.00%)
source.cssparsed: 0B(0.00%) gzip: 0B(0.00%)
source.jsparsed: 0B(0.00%) gzip: 0B(0.00%)
source.jsonparsed: 0B(0.00%) gzip: 0B(0.00%)
source.mdxparsed: 0B(0.00%) gzip: 0B(0.00%)
source.shellparsed: 0B(0.00%) gzip: 0B(0.00%)
source.tsparsed: 0B(0.00%) gzip: 0B(0.00%)
source.tsxparsed: 0B(0.00%) gzip: 0B(0.00%)
source.yamlparsed: 0B(0.00%) gzip: 0B(0.00%)
text.html.basicparsed: 0B(0.00%) gzip: 0B(0.00%)
text.mdparsed: 0B(0.00%) gzip: 0B(0.00%)
TransformEngineparsed: 0B(0.00%) gzip: 0B(0.00%)
transpileSourceparsed: 0B(0.00%) gzip: 0B(0.00%)

Details of bundle changes

Performance

Total duration: 16.25 ms +0.67 ms(+4.3%) | Renders: 5 (+0) | Paint: 58.98 ms +3.20 ms(+5.7%)

Test Duration Renders
Counter click 4.06 ms -0.09 ms(-2.0%) 2 (+0)
DataGrid mount with paint timing 2.14 ms -0.01 ms(-0.5%) 1 (+0)

5 tests within noise — details

Metric alarms

Test Metric Change
Counter click bench:paint 🔺 +2.65 ms
DataGrid mount with paint timing bench:paint#grid-header 🔺 +2.24 ms
DataGrid mount with paint timing bench:paint#grid-body 🔺 +2.24 ms
DataGrid mount with paint timing bench:paint 🔺 +2.24 ms

Check out the code infra dashboard for more information about this PR.

A host with its own editor — Material UI's `DemoEditor`, with its styling,
focus hint, and error overlay — had no way to drive a docs-infra block:
editing meant adopting docs-infra's editor DOM.

`editorMode: 'headless'` mounts no editor. The rendered file stays
highlighted, read-only source, and `useCode` returns what a host needs to
edit it: `selectedFileSource` as plain text, decoded from whichever shape
the source arrived in; `selectedFileProjection` for a collapsed view;
`selectedFileLanguage` and `selectedFileOriginalName`;
`selectedFileEditable`; and `activateEditing` to warm the edit-time engine
on focus. Edits go back through the same `setSource` the internal editor
uses, so the controller, reset behaviour, and preview are unchanged.

Decoding is skipped in `'internal'` mode, where nothing reads the text and
a `hastCompressed` payload would pay an inflate for it.

`useFileNavigation` also resolves the selected file's projection now, and
forwards it to `<Pre>` — the precompute has produced one since the preview
resolver landed, but nothing carried it to the editor.
@brijeshb42
brijeshb42 force-pushed the di-migration-collapse-reset branch from 260a65b to 0d4b10e Compare August 14, 2026 18:43
@brijeshb42
brijeshb42 force-pushed the di-migration-headless-source branch from 9e45aac to b4dde9f Compare August 14, 2026 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: docs-infra Involves the docs-infra product (https://www.notion.so/mui-org/b9f676062eb94747b6768209f7751305).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant