Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

_app.tsx 2.2 KB

You have to be logged in to leave a comment. Sign In
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
  1. import React, { useEffect } from 'react'
  2. import App from 'next/app'
  3. import type { AppProps, AppContext } from 'next/app'
  4. import Head from 'next/head'
  5. import { useTheme, ThemeProvider } from '@primer/components'
  6. import { defaultThemeProps, getThemeProps } from 'components/lib/getThemeProps'
  7. import '../stylesheets/index.scss'
  8. import events from 'javascripts/events'
  9. import experiment from 'javascripts/experiment'
  10. import setNextEnv from 'javascripts/set-next-env'
  11. type MyAppProps = AppProps & { csrfToken: string; themeProps: typeof defaultThemeProps }
  12. const MyApp = ({ Component, pageProps, csrfToken, themeProps }: MyAppProps) => {
  13. useEffect(() => {
  14. events()
  15. experiment()
  16. setNextEnv()
  17. }, [])
  18. return (
  19. <>
  20. <Head>
  21. <meta charSet="utf-8" />
  22. <title>GitHub Documentation</title>
  23. <meta name="viewport" content="width=device-width, initial-scale=1" />
  24. <link rel="alternate icon" type="image/png" href="/assets/images/site/favicon.png" />
  25. <link rel="icon" type="image/svg+xml" href="/assets/images/site/favicon.svg" />
  26. <meta
  27. name="google-site-verification"
  28. content="OgdQc0GZfjDI52wDv1bkMT-SLpBUo_h5nn9mI9L22xQ"
  29. />
  30. <meta
  31. name="google-site-verification"
  32. content="c1kuD-K2HIVF635lypcsWPoD4kilo5-jA_wBFyT4uMY"
  33. />
  34. <meta name="csrf-token" content={csrfToken} />
  35. </Head>
  36. <ThemeProvider>
  37. <SetTheme themeProps={themeProps} />
  38. <Component {...pageProps} />
  39. </ThemeProvider>
  40. </>
  41. )
  42. }
  43. MyApp.getInitialProps = async (appContext: AppContext) => {
  44. const { ctx } = appContext
  45. // calls page's `getInitialProps` and fills `appProps.pageProps`
  46. const appProps = await App.getInitialProps(appContext)
  47. const req: any = ctx.req
  48. return { ...appProps, themeProps: getThemeProps(req), csrfToken: req?.csrfToken?.() || '' }
  49. }
  50. const SetTheme = ({ themeProps }: { themeProps: typeof defaultThemeProps }) => {
  51. // Cause primer/components to re-evaluate the 'auto' color mode on client side render
  52. const { setColorMode } = useTheme()
  53. useEffect(() => {
  54. setTimeout(() => {
  55. setColorMode(themeProps.colorMode as any)
  56. })
  57. }, [])
  58. return null
  59. }
  60. export default MyApp
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...