Skip to content

[docs-infra] Keep source inputs stable - #2125

Draft
brijeshb42 wants to merge 5 commits into
masterfrom
docs-infra/idle-editor
Draft

brijeshb42 wants to merge 5 commits into
masterfrom
docs-infra/idle-editor

Conversation

@brijeshb42

@brijeshb42 brijeshb42 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Keep the source input mounted while editing tools load, so the first click can place the caret without idle initialization.

  • Source inputs render with the page. Opt into NativeCodeSource for full files and contiguous focus snippets. The server renders a readonly textarea with the precomputed highlight; hydration binds editing to the same input. Other renderers keep their existing lazy path.

    import { NativeCodeSource } from '@mui/internal-docs-infra/NativeCodeSource';
    
    const code = useCode(props, { SourceComponent: NativeCodeSource });
  • Initialization preserves selection and undo. Before, loading the editor replaced the highlighted preview. After, the input survives parser readiness, composition and typing. Runtime highlighting starts after an edit; initial source uses its precomputed tokens.

  • Undo respects the source view. edit snippet → expand → undo keeps the complete file. edit TypeScript → switch to JavaScript → undo keeps JavaScript. Changing views starts a new history; parser initialization preserves the current history.

  • Cold edits retain every file. Editing FocusedLiveEdit.tsx, message.ts and CSS before the source module loads previously kept only the CSS update. Pending edits now apply in order, preserving caret/focus metadata and the original preview; Reset cancels earlier pending work.

  • Deferred source stays compact. Contiguous source windows travel as a length and indentation when the existing fallback contains the exact text. CRLF or other mismatches retain the exact source. The 612 descriptors from the X build total 29,069 uncompressed bytes; this is added metadata, not a reduction against master.

Tests:

  • NativeCodeSource.browser.tsx: input identity, first typing, composition, undo and view/language history boundaries with the real provider.
  • useSourceEditing.lazyLoad.test.ts: real-engine cold multi-file edits, ordered caret/newline metadata and Reset followed by fresh edits.
  • deferredSource.test.tsx: server-rendered input through the deferred loader, compact descriptors and exact CRLF windows.

Verification: 6,503 unit tests and 106 browser tests pass; types, lint, release build, generated docs and packed modules pass. The two undo failures reproduced in the production integration and passed with the new package. Default renderer entry points exclude the editor vendor and parser engine.

Consumer integrations: material-ui#49910, mui-x#23851. Both final consumer deployments pass their source-editing and undo checks. Their PR descriptions contain 12-pair Lighthouse results: score changes are inconclusive, Material desktop TBT adds 3.5 ms, and X mobile TBT remains uncertain. The late input-replacement regression is resolved; no zero-cost claim is made.

@code-infra-dashboard

code-infra-dashboard Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Deploy preview

Bundle size

Total Size Change: 🔺+77KB(+2.35%) - Total Gzip Change: 🔺+28KB(+3.24%)
Files: 80 total (1 added, 0 removed, 6 changed)

Show details for 80 more bundles

CodeEditor parsed: 🔺+1.35KB(+10.10%) gzip: 🔺+453B(+8.37%)
@mui/internal-docs-infra/useDemo parsed: 🔺+1.16KB(+1.83%) gzip: 🔺+508B(+2.48%)
@mui/internal-docs-infra/useCode parsed: 🔺+1.15KB(+2.63%) gzip: 🔺+512B(+3.64%)
@mui/internal-docs-infra/CodeHighlighter parsed: 🔺+562B(+11.40%) gzip: 🔺+240B(+12.33%)
CodeHighlighterChunk parsed: 🔺+290B(+4.00%) gzip: 🔺+130B(+4.80%)
@mui/internal-docs-infra/CodeProvider parsed: 🔺+76B(+0.06%) gzip: 🔺+9B(+0.02%)
@mui/internal-docs-infra/NativeCodeSource parsed: 🔺+72.4KB(new) gzip: 🔺+26.1KB(new)
@mui/internal-docs-infra/abstractCreateDemo parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/abstractCreateDemoClient parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/abstractCreateStream parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/abstractCreateTypes parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/ChunkProvider parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/cli parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeControllerContext parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeExternalsContext parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeHighlighter/errors parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeHighlighter/types parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CoordinatedLazy parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CoordinatedLazy/types parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/createDemoData parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/createDemoData/types parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/createSitemap parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/createSitemap/types parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/resolvePageUrl parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/routeGroups parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useCodeWindow parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useCoordinated parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useCopier parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useDemoController parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useErrors parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useLocalStorageState parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/usePreference parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useScrollAnchor parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useSearch parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useSearch/types parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useStream parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useStream/types parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useType parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useTypes parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useUrlHashState parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/withDocsInfra parsed: 0B(0.00%) gzip: 0B(0.00%)
addLineGutters parsed: 0B(0.00%) gzip: 0B(0.00%)
applyCodeTransformWithComments parsed: 0B(0.00%) gzip: 0B(0.00%)
BuildEngine parsed: 0B(0.00%) gzip: 0B(0.00%)
CodeHighlighterClient parsed: 0B(0.00%) gzip: 0B(0.00%)
CodeInitialSourceLoader parsed: 0B(0.00%) gzip: 0B(0.00%)
CodeSourceLoader parsed: 0B(0.00%) gzip: 0B(0.00%)
compileCssWithPostcss parsed: 0B(0.00%) gzip: 0B(0.00%)
computeHastDeltas parsed: 0B(0.00%) gzip: 0B(0.00%)
createFrame parsed: 0B(0.00%) gzip: 0B(0.00%)
createParseSourceWorkerClient parsed: 0B(0.00%) gzip: 0B(0.00%)
embedTransforms parsed: 0B(0.00%) gzip: 0B(0.00%)
enhanceCodeEmphasis parsed: 0B(0.00%) gzip: 0B(0.00%)
findExpandingRanges parsed: 0B(0.00%) gzip: 0B(0.00%)
frameVisibility parsed: 0B(0.00%) gzip: 0B(0.00%)
getHastTextContent parsed: 0B(0.00%) gzip: 0B(0.00%)
grammarCache parsed: 0B(0.00%) gzip: 0B(0.00%)
grammarLoaders parsed: 0B(0.00%) gzip: 0B(0.00%)
grammarMaps parsed: 0B(0.00%) gzip: 0B(0.00%)
grammars parsed: 0B(0.00%) gzip: 0B(0.00%)
hastUtils parsed: 0B(0.00%) gzip: 0B(0.00%)
isFrameSpan parsed: 0B(0.00%) gzip: 0B(0.00%)
loadCodeFallback parsed: 0B(0.00%) gzip: 0B(0.00%)
loadIsomorphicCodeVariant parsed: 0B(0.00%) gzip: 0B(0.00%)
parseSource parsed: 0B(0.00%) gzip: 0B(0.00%)
rolldown-runtime parsed: 0B(0.00%) gzip: 0B(0.00%)
source.css parsed: 0B(0.00%) gzip: 0B(0.00%)
source.diff parsed: 0B(0.00%) gzip: 0B(0.00%)
source.js parsed: 0B(0.00%) gzip: 0B(0.00%)
source.json parsed: 0B(0.00%) gzip: 0B(0.00%)
source.mdx parsed: 0B(0.00%) gzip: 0B(0.00%)
source.shell parsed: 0B(0.00%) gzip: 0B(0.00%)
source.ts parsed: 0B(0.00%) gzip: 0B(0.00%)
source.tsx parsed: 0B(0.00%) gzip: 0B(0.00%)
source.yaml parsed: 0B(0.00%) gzip: 0B(0.00%)
SourceEditingEngine parsed: 0B(0.00%) gzip: 0B(0.00%)
text.html.basic parsed: 0B(0.00%) gzip: 0B(0.00%)
text.md parsed: 0B(0.00%) gzip: 0B(0.00%)
TransformEngine parsed: 0B(0.00%) gzip: 0B(0.00%)
transpileSource parsed: 0B(0.00%) gzip: 0B(0.00%)

Details of bundle changes

Performance

No regressions in 12 benchmarks · precise to ±18.0% (±41.4% at worst) · ran 1m 23s · details


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

@brijeshb42 brijeshb42 added scope: docs-infra Involves the docs-infra product (https://www.notion.so/mui-org/b9f676062eb94747b6768209f7751305). type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. test labels Nov 25, 2026
@brijeshb42 brijeshb42 changed the title [docs-infra] Initialize visible editors during idle [docs-infra] Expose editor preparation Nov 26, 2026
@brijeshb42
brijeshb42 force-pushed the docs-infra/idle-editor branch from 03d54d3 to cc210e0 Compare November 27, 2026 06:15
@brijeshb42 brijeshb42 changed the title [docs-infra] Expose editor preparation [docs-infra] Keep source inputs stable Nov 27, 2026
@brijeshb42
brijeshb42 force-pushed the docs-infra/idle-editor branch from 3a6cdd0 to fd6221e Compare December 5, 2026 06:40
brijeshb42 added a commit to brijeshb42/material-ui that referenced this pull request Dec 5, 2026
mui/mui-public#2125 was rebased onto master; point the preview
dependency at its new pkg.pr.new build.
brijeshb42 added a commit to brijeshb42/mui-x that referenced this pull request Dec 5, 2026
Pick up mui/mui-public#2125 after its rebase and
mui/material-ui#49910, which mounts the live source editor on
interaction instead of after load.
With editActivation 'interaction', a click on the static source loads
the editor and focuses its textarea at offset 0, so the first click
moves the caret to the start of the file. Map the click point onto
the editor's mirror <pre> once it mounts and select that offset.

Consumers need this to drop the eager NativeCodeSource mount, whose
repaint became LCP on anchored docs pages.
brijeshb42 added a commit to brijeshb42/material-ui that referenced this pull request Dec 5, 2026
Picks up mui/mui-public#2125, which places the caret at the clicked
point when the editor mounts on interaction.
brijeshb42 added a commit to brijeshb42/mui-x that referenced this pull request Dec 5, 2026
Pick up mui/mui-public#2125 and mui/material-ui#49910: the editor
now mounts on the first interaction, with the caret at the clicked
point, instead of replacing the static source after load. Update the
website specs to that contract.
brijeshb42 added a commit to brijeshb42/mui-x that referenced this pull request Dec 5, 2026
Pick up mui/mui-public#2125 and mui/material-ui#49910: the editor
now mounts on the first interaction, with the caret at the clicked
point, instead of replacing the static source after load. Update the
website specs to that contract.
brijeshb42 added a commit to brijeshb42/mui-x that referenced this pull request Dec 5, 2026
Pick up mui/mui-public#2125 and mui/material-ui#49910: the editor
now mounts on the first interaction, with the caret at the clicked
point, instead of replacing the static source after load. Update the
website specs to that contract.

This branch has not been deployed

No deployments
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). test type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant