forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_app.tsx
84 lines (73 loc) · 2.64 KB
/
_app.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import React, { useEffect } from 'react'
import App from 'next/app'
import type { AppProps, AppContext } from 'next/app'
import Head from 'next/head'
import { useTheme, ThemeProvider } from '@primer/components'
import { SSRProvider } from '@react-aria/ssr'
import { defaultComponentThemeProps, getThemeProps } from 'components/lib/getThemeProps'
import '../stylesheets/index.scss'
import events from 'components/lib/events'
import experiment from 'components/lib/experiment'
import { LanguagesContext, LanguagesContextT } from 'components/context/LanguagesContext'
type MyAppProps = AppProps & {
csrfToken: string
themeProps: typeof defaultComponentThemeProps
languagesContext: LanguagesContextT
}
const MyApp = ({ Component, pageProps, csrfToken, themeProps, languagesContext }: MyAppProps) => {
useEffect(() => {
events()
experiment()
}, [])
return (
<>
<Head>
<meta charSet="utf-8" />
<title>GitHub Documentation</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="alternate icon" type="image/png" href="/assets/images/site/favicon.png" />
<link rel="icon" type="image/svg+xml" href="/assets/images/site/favicon.svg" />
<meta
name="google-site-verification"
content="OgdQc0GZfjDI52wDv1bkMT-SLpBUo_h5nn9mI9L22xQ"
/>
<meta
name="google-site-verification"
content="c1kuD-K2HIVF635lypcsWPoD4kilo5-jA_wBFyT4uMY"
/>
<meta name="csrf-token" content={csrfToken} />
</Head>
<SSRProvider>
<ThemeProvider dayScheme={themeProps.dayTheme} nightScheme={themeProps.nightTheme}>
<LanguagesContext.Provider value={languagesContext}>
<SetTheme themeProps={themeProps} />
<Component {...pageProps} />
</LanguagesContext.Provider>
</ThemeProvider>
</SSRProvider>
</>
)
}
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
return {
...appProps,
themeProps: getThemeProps(req),
csrfToken: req?.csrfToken?.() || '',
languagesContext: { languages: req.context.languages },
}
}
const SetTheme = ({ themeProps }: { themeProps: typeof defaultComponentThemeProps }) => {
// Cause primer/components to re-evaluate the 'auto' color mode on client side render
const { setColorMode } = useTheme()
useEffect(() => {
setTimeout(() => {
setColorMode(themeProps.colorMode as any)
})
}, [])
return null
}
export default MyApp