root.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import {Fragment, useEffect, useContext} from 'react';
  2. import {createPortal} from 'react-dom';
  3. import {browserHistory, Router, RouterContext} from 'react-router';
  4. import {cache} from '@emotion/css'; // eslint-disable-line @emotion/no-vanilla
  5. import {CacheProvider, ThemeProvider} from '@emotion/react'; // This is needed to set "speedy" = false (for percy)
  6. import {
  7. Links,
  8. LiveReload,
  9. Meta,
  10. Outlet,
  11. Scripts,
  12. ScrollRestoration,
  13. } from '@remix-run/react';
  14. import {loadPreferencesState} from 'sentry/actionCreators/preferences';
  15. import DemoHeader from 'sentry/components/demo/demoHeader';
  16. import {routes} from 'sentry/routes';
  17. import ConfigStore from 'sentry/stores/configStore';
  18. import {PersistedStoreProvider} from 'sentry/stores/persistedStore';
  19. import {useLegacyStore} from 'sentry/stores/useLegacyStore';
  20. import GlobalStyles from 'sentry/styles/global';
  21. import {darkTheme, lightTheme} from 'sentry/utils/theme';
  22. import {RouteContext} from 'sentry/views/routeContext';
  23. import StylesContext from './stylesContext';
  24. type Props = {
  25. children: React.ReactNode;
  26. };
  27. /**
  28. * Wraps children with emotions ThemeProvider reactively set a theme.
  29. *
  30. * Also injects the sentry GlobalStyles .
  31. */
  32. function ThemeAndStyleProvider({children}: Props) {
  33. useEffect(() => void loadPreferencesState(), []);
  34. const config = useLegacyStore(ConfigStore);
  35. const theme = config.theme === 'dark' ? darkTheme : lightTheme;
  36. return (
  37. <ThemeProvider theme={theme}>
  38. <GlobalStyles isDark={config.theme === 'dark'} theme={theme} />
  39. <CacheProvider value={cache}>{children}</CacheProvider>
  40. </ThemeProvider>
  41. );
  42. }
  43. export default function App() {
  44. // get styles from context
  45. return (
  46. <html lang="en">
  47. <head>
  48. <Meta />
  49. <Links />
  50. <link
  51. href="https://s1.sentry-cdn.com/_static/dist/sentry/entrypoints/sentry.css"
  52. rel="stylesheet"
  53. />
  54. </head>
  55. <body>
  56. <ThemeAndStyleProvider>
  57. <PersistedStoreProvider>
  58. <Outlet />
  59. <ScrollRestoration />
  60. <Scripts />
  61. </PersistedStoreProvider>
  62. </ThemeAndStyleProvider>
  63. </body>
  64. </html>
  65. );
  66. }