import React, { useEffect } from 'react' import App from 'next/app' import type { AppProps, AppContext } from 'next/app' import Head from 'next/head' import { ThemeProvider, ThemeProviderProps } from '@primer/react' import { SSRProvider } from '@react-aria/ssr' import '../stylesheets/index.scss' import events from 'components/lib/events' import experiment from 'components/lib/experiment' import { LanguagesContext, LanguagesContextT } from 'components/context/LanguagesContext' import { DotComAuthenticatedContext, DotComAuthenticatedContextT, } from 'components/context/DotComAuthenticatedContext' import { defaultComponentTheme } from 'lib/get-theme.js' type MyAppProps = AppProps & { csrfToken: string isDotComAuthenticated: boolean themeProps: typeof defaultComponentTheme & Pick languagesContext: LanguagesContextT dotComAuthenticatedContext: DotComAuthenticatedContextT } const MyApp = ({ Component, pageProps, csrfToken, themeProps, languagesContext, dotComAuthenticatedContext, }: MyAppProps) => { useEffect(() => { events() experiment() }, []) return ( <> GitHub Documentation {/* The value in these "/cb-xxxxx" prefixes aren't important. They just need to be present. They help the CDN cache the asset for infinity. Just remember, if you edit these images on disk, remember to change these numbers */} ) } // Remember, function is only called once if the rendered page can // be in-memory cached. But still, the `` component will be // executed every time **in the client** if it was the first time // ever (since restart) or from a cached HTML. MyApp.getInitialProps = async (appContext: AppContext) => { const { ctx } = appContext // calls page's `getInitialProps` and fills `appProps.pageProps` const appProps = await App.getInitialProps(appContext) const req: any = ctx.req const { getTheme } = await import('lib/get-theme.js') return { ...appProps, themeProps: getTheme(req), csrfToken: req?.csrfToken?.() || '', languagesContext: { languages: req.context.languages, userLanguage: req.context.userLanguage }, dotComAuthenticatedContext: { isDotComAuthenticated: Boolean(req.cookies?.dotcom_user) }, } } export default MyApp