[docs-infra] Extract shared App component from _app into @mui/docs#47933
Conversation
Netlify deploy previewhttps://deploy-preview-47933--material-ui.netlify.app/ Bundle size report
|
de42f91 to
aedfd8c
Compare
aedfd8c to
b6c2edb
Compare
b6c2edb to
e7b5a04
Compare
59ce4e3 to
d76d8de
Compare
d76d8de to
2c9c958
Compare
01464c2 to
e5aacf9
Compare
Janpot
left a comment
There was a problem hiding this comment.
Seems good, would consider tweaking the API a bit, such that we assemble contexts inside of the component, not outside.
8d72564 to
350e2ae
Compare
| if (productId === 'system') { | ||
| return 'MUI System'; | ||
| } | ||
| if (productId?.startsWith('x-')) { |
There was a problem hiding this comment.
Which pages would hit this branch?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Just asking because I don't think it will ever be reached in this app
There was a problem hiding this comment.
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.
350e2ae to
0683b28
Compare
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.
Also renamed some
0683b28 to
eda05f3
Compare
| } | ||
|
|
||
| // TODO: 'core' is a productCategoryId, not a productId — this branch may be dead code. | ||
| if ((productId as string) === 'core') { |
There was a problem hiding this comment.
why does this need a cast and the other checks don't?
There was a problem hiding this comment.
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.
siriwatknp
left a comment
There was a problem hiding this comment.
I don't see emotionCache used in the new _app.tsx, is it expected?
siriwatknp
left a comment
There was a problem hiding this comment.
Ah, okay. It's in DocsApp.tsx.
Create a configurable
<DocsApp>component in@mui/docs/DocsAppthat encapsulates the common provider tree and boilerplate previously duplicated between material-ui and mui-x_appfiles.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 (webpackrequire.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,codeVariantandcodeStylingto typescript.Type fixes in PageContext when converting to typescript:
productCategoryIdtoMuiPageContextinterface (was passed at runtime but missing from the type).Added
docs/types/webpack.d.ts declaring require.context() on NodeJS.Require to support the TypeScript conversion.