-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.tsx
81 lines (73 loc) · 2.75 KB
/
main.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
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* Copyright Oxide Computer Company
*/
import { QueryClientProvider } from '@tanstack/react-query'
// import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import { createBrowserRouter, RouterProvider } from 'react-router-dom'
import { queryClient } from '@oxide/api'
import { ConfirmActionModal } from './components/ConfirmActionModal'
import { ErrorBoundary } from './components/ErrorBoundary'
import { ReduceMotion } from './hooks/use-reduce-motion'
// stripped out by rollup in production
import { startMockAPI } from './msw-mock-api'
import { routes } from './routes'
// this is the only allowed css import
// eslint-disable-next-line no-restricted-imports
import '~/ui/styles/index.css'
import { SkipLink } from '~/ui/lib/SkipLink'
if (process.env.SHA) {
console.info(
'Oxide Web Console version',
`https://github.com/oxidecomputer/console/commits/${process.env.SHA}`
)
}
const root = createRoot(document.getElementById('root')!)
function render() {
// createBrowserRouter kicks off the loaders, which is weird because you'd
// think route matching hasn't happened yet, but apparently it does its own
// matching. I asked about this on Discord and they said it's intentional.
// This means RR is best thought of as an external store that runs
// independently of the React render lifecycle.
const router = createBrowserRouter(routes, {
// https://reactrouter.com/en/6.24.0/upgrading/future
future: {
v7_fetcherPersist: true,
v7_normalizeFormMethod: true,
v7_partialHydration: true,
v7_relativeSplatPath: true,
v7_skipActionErrorRevalidation: true,
},
})
root.render(
<StrictMode>
<QueryClientProvider client={queryClient}>
<ErrorBoundary>
<ConfirmActionModal />
<SkipLink id="skip-nav" />
<ReduceMotion />
<RouterProvider
router={router}
// this breaks the scroll restore test. turn it on after we change
// the layout so the whole page scrolls and switch back to RR's
// built in useScrollRestoration
// future={{ v7_startTransition: true }}
/>
</ErrorBoundary>
{/* <ReactQueryDevtools initialIsOpen={false} /> */}
</QueryClientProvider>
</StrictMode>
)
}
if (process.env.MSW) {
// MSW has NODE_ENV !== prod built into it, but let's be extra safe
// need to defer requests until after the mock server starts up
startMockAPI().then(render)
} else {
render()
}