Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs-infra] Sync _app file with monorepo #3698

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 33 additions & 23 deletions docs/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,28 @@ import { ponyfillGlobal } from '@mui/utils';
import { LicenseInfo } from '@mui/x-license';
import PageContext from 'docs/src/modules/components/PageContext';
import GoogleAnalytics from 'docs/src/modules/components/GoogleAnalytics';
import { CodeCopyProvider } from '@mui/docs/CodeCopy';
import { ThemeProvider } from 'docs/src/modules/components/ThemeContext';
import { CodeVariantProvider } from 'docs/src/modules/utils/codeVariant';
import { CodeCopyProvider } from 'docs/src/modules/utils/CodeCopy';
import { CodeStylingProvider } from 'docs/src/modules/utils/codeStylingSolution';
import DocsStyledEngineProvider from 'docs/src/modules/utils/StyledEngineProvider';
import { pathnameToLanguage } from 'docs/src/modules/utils/helpers';
import createEmotionCache from 'docs/src/createEmotionCache';
import findActivePage from 'docs/src/modules/utils/findActivePage';
import { pathnameToLanguage } from 'docs/src/modules/utils/helpers';
import getProductInfoFromUrl from 'docs/src/modules/utils/getProductInfoFromUrl';
import toolpadPkgJson from '@toolpad/studio/package.json';
import { DocsProvider } from '@mui/docs/DocsProvider';
import toolpadStudioPages from '../data/toolpad/studio/pages';
import toolpadCorePages from '../data/toolpad/core/pages';
import config from '../config';

// Remove the license warning from demonstration purposes
LicenseInfo.setLicenseKey(process.env.NEXT_PUBLIC_MUI_LICENSE);

// Client-side cache, shared for the whole session of the user in the browser.
const clientSideEmotionCache = createEmotionCache();

let reloadInterval;
LicenseInfo.setLicenseKey(process.env.NEXT_PUBLIC_MUI_LICENSE);

function getMuiPackageVersion(packageName, commitRef) {
if (commitRef === undefined) {
Expand Down Expand Up @@ -154,15 +158,18 @@ if (typeof window !== 'undefined' && process.env.NODE_ENV === 'production') {
██║ ╚═╝ ██║ ╚██████╔╝ ██████╗
╚═╝ ╚═╝ ╚═════╝ ╚═════╝

Tip: you can access the documentation \`theme\` object directly in the console.
`,
'font-family:monospace;color:#1976d2;font-size:12px;',
);
}

function AppWrapper(props) {
const { children, emotionCache, pageProps } = props;

const router = useRouter();
// TODO move productId & productCategoryId resolution to page layout.
// We should use the productId field from the markdown and fallback to getProductInfoFromUrl()
// if not present
const { productId, productCategoryId } = getProductInfoFromUrl(router.asPath);

React.useEffect(() => {
Expand All @@ -176,13 +183,6 @@ function AppWrapper(props) {
}
}, []);

let fonts = [];
if (pathnameToLanguage(router.asPath).canonicalAs.match(/onepirate/)) {
fonts = [
'https://fonts.googleapis.com/css?family=Roboto+Condensed:700|Work+Sans:300,400&display=swap',
];
}

const pageContextValue = React.useMemo(() => {
let productIdentifier;
let pages = [];
Expand Down Expand Up @@ -250,6 +250,13 @@ function AppWrapper(props) {
};
}, [router.asPath, router.pathname, productId, productCategoryId]);

let fonts = [];
if (pathnameToLanguage(router.asPath).canonicalAs.match(/onepirate/)) {
fonts = [
'https://fonts.googleapis.com/css2?family=Roboto+Condensed:wght@700&family=Work+Sans:wght@300;400&display=swap',
];
}

return (
<React.Fragment>
<NextHead>
Expand All @@ -261,16 +268,18 @@ function AppWrapper(props) {
</NextHead>
<DocsProvider config={config} defaultUserLanguage={pageProps.userLanguage}>
<CodeCopyProvider>
<CodeVariantProvider>
<PageContext.Provider value={pageContextValue}>
<ThemeProvider>
<DocsStyledEngineProvider cacheLtr={emotionCache}>
{children}
<GoogleAnalytics />
</DocsStyledEngineProvider>
</ThemeProvider>
</PageContext.Provider>
</CodeVariantProvider>
<CodeStylingProvider>
<CodeVariantProvider>
<PageContext.Provider value={pageContextValue}>
<ThemeProvider>
<DocsStyledEngineProvider cacheLtr={emotionCache}>
{children}
<GoogleAnalytics />
</DocsStyledEngineProvider>
</ThemeProvider>
</PageContext.Provider>
</CodeVariantProvider>
</CodeStylingProvider>
</CodeCopyProvider>
</DocsProvider>
</React.Fragment>
Expand All @@ -285,14 +294,14 @@ AppWrapper.propTypes = {

export default function MyApp(props) {
const { Component, emotionCache = clientSideEmotionCache, pageProps } = props;
const getLayout = Component.getLayout ?? ((page) => page);

return (
<AppWrapper emotionCache={emotionCache} pageProps={pageProps}>
<Component {...pageProps} />
{getLayout(<Component {...pageProps} />)}
</AppWrapper>
);
}

MyApp.propTypes = {
Component: PropTypes.elementType.isRequired,
emotionCache: PropTypes.object,
Expand All @@ -316,6 +325,7 @@ MyApp.getInitialProps = async ({ ctx, Component }) => {

// Track fraction of actual events to prevent exceeding event quota.
// Filter sessions instead of individual events so that we can track multiple metrics per device.
// See https://github.com/GoogleChromeLabs/web-vitals-report to use this data
const disableWebVitalsReporting = Math.random() > 0.0001;
export function reportWebVitals({ id, name, label, delta, value }) {
if (disableWebVitalsReporting) {
Expand Down
Loading