main.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {Router, RouterContext} from 'react-router';
  2. import {createBrowserRouter, RouterProvider} from 'react-router-dom';
  3. import {ReactQueryDevtools} from '@tanstack/react-query-devtools';
  4. import DemoHeader from 'sentry/components/demo/demoHeader';
  5. import {OnboardingContextProvider} from 'sentry/components/onboarding/onboardingContext';
  6. import {ThemeAndStyleProvider} from 'sentry/components/themeAndStyleProvider';
  7. import {USE_REACT_QUERY_DEVTOOL, USING_REACT_ROUTER_SIX} from 'sentry/constants';
  8. import {routes, routes6} from 'sentry/routes';
  9. import ConfigStore from 'sentry/stores/configStore';
  10. import {
  11. browserHistory,
  12. DANGEROUS_SET_REACT_ROUTER_6_HISTORY,
  13. } from 'sentry/utils/browserHistory';
  14. import {
  15. DEFAULT_QUERY_CLIENT_CONFIG,
  16. QueryClient,
  17. QueryClientProvider,
  18. } from 'sentry/utils/queryClient';
  19. import {RouteContext} from 'sentry/views/routeContext';
  20. import RouteAnalyticsContextProvider from './views/routeAnalyticsContextProvider';
  21. /**
  22. * Renders our compatibility RouteContext.Provider. This will go away with
  23. * react-router v6.
  24. */
  25. function renderRouter(props: any) {
  26. return (
  27. <RouteAnalyticsContextProvider {...props}>
  28. <RouteContext.Provider value={props}>
  29. <RouterContext {...props} />
  30. </RouteContext.Provider>
  31. </RouteAnalyticsContextProvider>
  32. );
  33. }
  34. const queryClient = new QueryClient(DEFAULT_QUERY_CLIENT_CONFIG);
  35. const router = createBrowserRouter(routes6);
  36. if (USING_REACT_ROUTER_SIX) {
  37. DANGEROUS_SET_REACT_ROUTER_6_HISTORY(router);
  38. }
  39. function Main() {
  40. return (
  41. <ThemeAndStyleProvider>
  42. <QueryClientProvider client={queryClient}>
  43. <OnboardingContextProvider>
  44. {ConfigStore.get('demoMode') && <DemoHeader />}
  45. {USING_REACT_ROUTER_SIX ? (
  46. <RouterProvider router={router} />
  47. ) : (
  48. <Router history={browserHistory} render={renderRouter}>
  49. {routes()}
  50. </Router>
  51. )}
  52. </OnboardingContextProvider>
  53. {USE_REACT_QUERY_DEVTOOL && (
  54. <ReactQueryDevtools initialIsOpen={false} position="bottom-left" />
  55. )}
  56. </QueryClientProvider>
  57. </ThemeAndStyleProvider>
  58. );
  59. }
  60. export default Main;