[docs-infra] Extract shared App component from _app into @mui/docs by brijeshb42 · Pull Request #47933 · mui/material-ui (original) (raw)
Create a configurable 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.