Skip to content

Commit 2236fb4

Browse files
authored
Remix Development tools v2 (#386)
1 parent 512f920 commit 2236fb4

File tree

5 files changed

+980
-839
lines changed

5 files changed

+980
-839
lines changed

app/entry.client.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ if (ENV.MODE === 'production' && ENV.SENTRY_DSN) {
66
import('./utils/monitoring.client.tsx').then(({ init }) => init())
77
}
88

9-
startTransition(() => {
10-
hydrateRoot(document, <RemixBrowser />)
11-
})
9+
const callback = () =>
10+
startTransition(() => {
11+
hydrateRoot(document, <RemixBrowser />)
12+
})
13+
14+
if (process.env.NODE_ENV === 'development') {
15+
import('remix-development-tools').then(({ initClient }) => {
16+
// Add all the dev tools props here into the client
17+
initClient()
18+
callback()
19+
})
20+
} else {
21+
callback()
22+
}

app/entry.server.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,21 @@ export default async function handleRequest(...args: DocRequestArgs) {
3838
: 'onShellReady'
3939

4040
const nonce = String(loadContext.cspNonce) ?? undefined
41-
return new Promise((resolve, reject) => {
41+
return new Promise(async (resolve, reject) => {
4242
let didError = false
43-
43+
const context =
44+
process.env.NODE_ENV === 'development'
45+
? await import('remix-development-tools').then(({ initServer }) =>
46+
initServer(remixContext),
47+
)
48+
: remixContext
4449
// NOTE: this timing will only include things that are rendered in the shell
4550
// and will not include suspended components and deferred loaders
4651
const timings = makeTimings('render', 'renderToPipeableStream')
4752

4853
const { pipe, abort } = renderToPipeableStream(
4954
<NonceProvider value={nonce}>
50-
<RemixServer context={remixContext} url={request.url} />
55+
<RemixServer context={context} url={request.url} />
5156
</NonceProvider>,
5257
{
5358
[callbackName]: () => {

app/root.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
useSubmit,
2525
} from '@remix-run/react'
2626
import { withSentry } from '@sentry/remix'
27-
import { useRef } from 'react'
27+
import { Suspense, lazy, useRef } from 'react'
2828
import { z } from 'zod'
2929
import { Confetti } from './components/confetti.tsx'
3030
import { GeneralErrorBoundary } from './components/error-boundary.tsx'
@@ -59,6 +59,11 @@ import { type Theme, setTheme, getTheme } from './utils/theme.server.ts'
5959
import { makeTimings, time } from './utils/timing.server.ts'
6060
import { getToast } from './utils/toast.server.ts'
6161
import { useOptionalUser, useUser } from './utils/user.ts'
62+
63+
const RemixDevTools =
64+
process.env.NODE_ENV === 'development'
65+
? lazy(() => import('remix-development-tools'))
66+
: null
6267

6368
export const links: LinksFunction = () => {
6469
return [
@@ -277,8 +282,13 @@ function App() {
277282
<ThemeSwitch userPreference={data.requestInfo.userPrefs.theme} />
278283
</div>
279284
</div>
280-
<Confetti id={data.confettiId} />
281-
<EpicToaster toast={data.toast} />
285+
<Confetti id={data.confettiId} />
286+
<EpicToaster toast={data.toast} />
287+
{RemixDevTools ? (
288+
<Suspense>
289+
<RemixDevTools />
290+
</Suspense>
291+
) : null}
282292
</Document>
283293
)
284294
}

0 commit comments

Comments
 (0)