Skip to content

[docs-infra] Extract shared App component from _app into @mui/docs#47933

Merged
brijeshb42 merged 2 commits into
mui:masterfrom
brijeshb42:migrate-docs-app
Mar 16, 2026
Merged

[docs-infra] Extract shared App component from _app into @mui/docs#47933
brijeshb42 merged 2 commits into
mui:masterfrom
brijeshb42:migrate-docs-app

Conversation

@brijeshb42
Copy link
Copy Markdown
Contributor

@brijeshb42 brijeshb42 commented Mar 9, 2026

Create a configurable <DocsApp> component in @mui/docs/DocsApp that encapsulates the common provider tree and boilerplate previously duplicated between material-ui and mui-x _app files.

Followup to - #47897

New module: packages/mui-docs/src/DocsApp/

  • DocsApp.tsx: Configurable component rendering the full provider tree (DocsProvider → CodeCopyProvider → CodeStylingProvider → CodeVariantProvider → PageContext → DemoContext → ThemeWrapper → StyledEngineProvider → AnalyticsProvider → children + GoogleAnalytics). Accepts props for config, serviceWorkerPath, pageContextValue, demoContextValue, adConfig, ThemeWrapper, and onInit.
  • createGetInitialProps.ts: Factory for MyApp.getInitialProps, parameterized by translationsContext (webpack require.context). Follows the same pattern as @mui/docs/Document's createGetInitialProps.
  • reportWebVitals.ts: Shared reportWebVitals function.
  • printConsoleBanner.ts: Exported function for the MUI ASCII banner.
  • serviceWorker.ts: registerServiceWorker(swPath) parameterized by path.
  • loadDependencies.ts: Material Icons CSS font loading via fg-loadcss.

Moved into DocsApp/ (only used by DocsApp, no external consumers):

  • AnalyticsProvider.tsx (from src/AnalyticsProvider/)
  • GoogleAnalytics.tsx (from src/GoogleAnalytics/)
  • StyledEngineProvider.tsx (from src/StyledEngineProvider/)

Converted _app.js, _document.js, codeVariant and codeStyling to typescript.

Type fixes in PageContext when converting to typescript:

  • Added productCategoryId to MuiPageContext interface (was passed at runtime but missing from the type).
  • Relaxed ProductVersion to { text; current?; href? } to match actual usage (versions are either current or have an href link, not both required).

Added docs/types/webpack.d.ts declaring require.context() on NodeJS.Require to support the TypeScript conversion.

@brijeshb42 brijeshb42 added the scope: docs-infra Involves the docs-infra product (https://www.notion.so/mui-org/b9f676062eb94747b6768209f7751305). label Mar 9, 2026
@mui-bot
Copy link
Copy Markdown

mui-bot commented Mar 9, 2026

Netlify deploy preview

https://deploy-preview-47933--material-ui.netlify.app/

Bundle size report

Bundle Parsed size Gzip size
@mui/material 0B(0.00%) 0B(0.00%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes

Generated by 🚫 dangerJS against eda05f3

@brijeshb42 brijeshb42 force-pushed the migrate-docs-app branch 9 times, most recently from de42f91 to aedfd8c Compare March 10, 2026 06:11
@brijeshb42 brijeshb42 requested review from a team March 10, 2026 07:14
@brijeshb42 brijeshb42 marked this pull request as ready for review March 10, 2026 07:25
@brijeshb42 brijeshb42 force-pushed the migrate-docs-app branch 7 times, most recently from 59ce4e3 to d76d8de Compare March 11, 2026 11:07
@brijeshb42 brijeshb42 requested a review from Janpot March 11, 2026 11:15
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Mar 11, 2026
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Mar 11, 2026
@brijeshb42 brijeshb42 force-pushed the migrate-docs-app branch 2 times, most recently from 01464c2 to e5aacf9 Compare March 12, 2026 09:23
Comment thread docs/pages/_app.tsx Outdated
Copy link
Copy Markdown
Member

@Janpot Janpot left a comment

Choose a reason for hiding this comment

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

Seems good, would consider tweaking the API a bit, such that we assemble contexts inside of the component, not outside.

@brijeshb42 brijeshb42 force-pushed the migrate-docs-app branch 2 times, most recently from 8d72564 to 350e2ae Compare March 13, 2026 09:48
Comment thread docs/pages/_app.tsx
if (productId === 'system') {
return 'MUI System';
}
if (productId?.startsWith('x-')) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Which pages would hit this branch?

Copy link
Copy Markdown
Contributor Author

@brijeshb42 brijeshb42 Mar 13, 2026

Choose a reason for hiding this comment

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

As per the code, all pages like /x/react-<data-grid|datepickers|charts|tree-view>.
It might also be the case that its not needed here since mui-x already has this. I have not removed any of the existing logic, just re-arranged the components/props.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just asking because I don't think it will ever be reached in this app

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.

I think you are right. I can add a note to remove in a separate PR. I don't want to change any logic in this PR.

@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Mar 13, 2026
Create a configurable <DocsApp> component in @mui/docs/DocsApp that
encapsulates the common provider tree and boilerplate previously
duplicated between material-ui and mui-x _app files.

New module: packages/mui-docs/src/DocsApp/
- DocsApp.tsx: Configurable component rendering the full provider tree
  (DocsProvider → CodeCopyProvider → CodeStylingProvider →
  CodeVariantProvider → PageContext → DemoContext → ThemeWrapper →
  StyledEngineProvider → AnalyticsProvider → children + GoogleAnalytics).
  Accepts props for config, serviceWorkerPath, pageContextValue,
  demoContextValue, adConfig, ThemeWrapper, and onInit.
- createGetInitialProps.ts: Factory for MyApp.getInitialProps,
  parameterized by translationsContext (webpack require.context).
  Follows the same pattern as @mui/docs/Document's createGetInitialProps.
- reportWebVitals.ts: Shared reportWebVitals function.
- printConsoleBanner.ts: Exported function for the MUI ASCII banner.
- serviceWorker.ts: registerServiceWorker(swPath) parameterized by path.
- loadDependencies.ts: Material Icons CSS font loading via fg-loadcss.

Moved into DocsApp/ (only used by DocsApp, no external consumers):
- AnalyticsProvider.tsx (from src/AnalyticsProvider/)
- GoogleAnalytics.tsx (from src/GoogleAnalytics/)
- StyledEngineProvider.tsx (from src/StyledEngineProvider/)

Converted _app.js → _app.tsx and _document.js → _document.tsx in both
material-ui and mui-x docs, adding proper TypeScript annotations.

Type fixes in PageContext:
- Added productCategoryId to MuiPageContext interface (was passed at
  runtime but missing from the type).
- Relaxed ProductVersion to { text; current?; href? } to match actual
  usage (versions are either current or have an href link, not both
  required).

Added docs/types/webpack.d.ts declaring require.context() on
NodeJS.Require to support the TypeScript conversion.
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Mar 13, 2026
Comment thread docs/pages/_app.tsx
}

// TODO: 'core' is a productCategoryId, not a productId — this branch may be dead code.
if ((productId as string) === 'core') {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why does this need a cast and the other checks don't?

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.

We need a bit of cleanup in this logic. Its currently there mainly because I converted some of the code to typescript and this was what was caught in a ts issue since core is not a productId. So I cast it because I didn't want to touch any of the existing logic.

Copy link
Copy Markdown
Member

@siriwatknp siriwatknp left a comment

Choose a reason for hiding this comment

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

I don't see emotionCache used in the new _app.tsx, is it expected?

Copy link
Copy Markdown
Member

@siriwatknp siriwatknp left a comment

Choose a reason for hiding this comment

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

Ah, okay. It's in DocsApp.tsx.

@brijeshb42 brijeshb42 merged commit c5c1d83 into mui:master Mar 16, 2026
23 checks passed
@brijeshb42 brijeshb42 deleted the migrate-docs-app branch March 16, 2026 07:19
siriwatknp pushed a commit to siriwatknp/material-ui that referenced this pull request Mar 18, 2026
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.

5 participants