Skip to content

Commit be6d265

Browse files
authored
Better cloudflare support (#166)
* Potential cloudflare support * Cloudflare support * version bump
1 parent 6357263 commit be6d265

File tree

8 files changed

+42
-13
lines changed

8 files changed

+42
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,4 @@ dist
136136
# IDE
137137
.idea
138138
.tsup
139+
.react-router

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@ export default defineConfig({
5353

5454
That's it, you're done!
5555

56+
### CloudFlare
57+
58+
If you're trying to spin it up on CF, try adding this to your `optimizeDeps` in your `vite.config.js` file:
59+
```ts
60+
optimizeDeps: {
61+
include: [
62+
// other optimized deps
63+
"beautify",
64+
"react-diff-viewer-continued",
65+
"classnames",
66+
"@bkrem/react-transition-group",
67+
],
68+
},
69+
```
5670

5771
## Support
5872

docs/posts/main/started/installation.mdx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@ export default defineConfig({
4949
Make sure your plugin is BEFORE the react router one!
5050
</Warn>
5151

52+
### CloudFlare
53+
54+
If you're trying to spin it up on CF, try adding this to your `optimizeDeps` in your `vite.config.js` file:
55+
```ts
56+
optimizeDeps: {
57+
include: [
58+
// other optimized deps
59+
"beautify",
60+
"react-diff-viewer-continued",
61+
"classnames",
62+
"@bkrem/react-transition-group",
63+
],
64+
},
65+
```
66+
5267
**That's it!**
5368

5469
You should now see the React Router Devtools in your browser when you run your app.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "react-router-devtools",
33
"description": "Devtools for React Router - debug, trace, find hydration errors, catch bugs and inspect server/client data with react-router-devtools",
44
"author": "Alem Tuzlak",
5-
"version": "1.0.3",
5+
"version": "1.0.4",
66
"license": "MIT",
77
"keywords": [
88
"react-router",

src/vite/editor.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import { exec } from "node:child_process"
2-
import fs from "node:fs"
3-
import path from "node:path"
41
import { normalizePath } from "vite"
52
import { checkPath } from "./utils.js"
63

@@ -25,30 +22,32 @@ export type EditorConfig = {
2522

2623
export const DEFAULT_EDITOR_CONFIG: EditorConfig = {
2724
name: "VSCode",
28-
open: (path, lineNumber) => {
25+
open: async (path, lineNumber) => {
26+
const { exec } = await import("node:child_process")
2927
exec(`code -g "${normalizePath(path).replaceAll("$", "\\$")}${lineNumber ? `:${lineNumber}` : ""}"`)
3028
},
3129
}
3230

33-
export const handleOpenSource = ({
31+
export const handleOpenSource = async ({
3432
data,
3533
openInEditor,
3634
appDir,
3735
}: {
3836
data: OpenSourceData
3937
appDir: string
40-
openInEditor: (path: string, lineNum: string | undefined) => void
38+
openInEditor: (path: string, lineNum: string | undefined) => Promise<void>
4139
}) => {
4240
const { source, line, routeID } = data.data
4341
const lineNum = line ? `${line}` : undefined
44-
42+
const fs = await import("node:fs")
43+
const path = await import("node:path")
4544
if (source) {
4645
return openInEditor(source, lineNum)
4746
}
4847

4948
if (routeID) {
5049
const routePath = path.join(appDir, routeID)
51-
const checkedPath = checkPath(routePath)
50+
const checkedPath = await checkPath(routePath)
5251

5352
if (!checkedPath) return
5453
const { type, validPath } = checkedPath

src/vite/plugin.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
215215
)
216216
})
217217
const editor = args?.editor ?? DEFAULT_EDITOR_CONFIG
218-
const openInEditor = (path: string | undefined, lineNum: string | undefined) => {
218+
const openInEditor = async (path: string | undefined, lineNum: string | undefined) => {
219219
if (!path) {
220220
return
221221
}

src/vite/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import fs from "node:fs"
21
import type { IncomingMessage, ServerResponse } from "node:http"
32
import type { Connect } from "vite"
43

@@ -49,7 +48,8 @@ export const handleDevToolsViteRequest = (
4948
})
5049
}
5150

52-
export function checkPath(routePath: string, extensions = [".tsx", ".jsx", ".ts", ".js"]) {
51+
export async function checkPath(routePath: string, extensions = [".tsx", ".jsx", ".ts", ".js"]) {
52+
const fs = await import("node:fs")
5353
// Check if the path exists as a directory
5454
if (fs.existsSync(routePath) && fs.lstatSync(routePath).isDirectory()) {
5555
return { validPath: routePath, type: "directory" } as const
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22
import { flatRoutes } from "@react-router/fs-routes";
3-
export const routes = flatRoutes()
3+
export default flatRoutes()

0 commit comments

Comments
 (0)