Skip to content

Commit

Permalink
Better cloudflare support (#166)
Browse files Browse the repository at this point in the history
* Potential cloudflare support

* Cloudflare support

* version bump
  • Loading branch information
AlemTuzlak authored Nov 23, 2024
1 parent 6357263 commit be6d265
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,4 @@ dist
# IDE
.idea
.tsup
.react-router
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ export default defineConfig({

That's it, you're done!

### CloudFlare

If you're trying to spin it up on CF, try adding this to your `optimizeDeps` in your `vite.config.js` file:
```ts
optimizeDeps: {
include: [
// other optimized deps
"beautify",
"react-diff-viewer-continued",
"classnames",
"@bkrem/react-transition-group",
],
},
```

## Support

Expand Down
15 changes: 15 additions & 0 deletions docs/posts/main/started/installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ export default defineConfig({
Make sure your plugin is BEFORE the react router one!
</Warn>

### CloudFlare

If you're trying to spin it up on CF, try adding this to your `optimizeDeps` in your `vite.config.js` file:
```ts
optimizeDeps: {
include: [
// other optimized deps
"beautify",
"react-diff-viewer-continued",
"classnames",
"@bkrem/react-transition-group",
],
},
```

**That's it!**

You should now see the React Router Devtools in your browser when you run your app.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "react-router-devtools",
"description": "Devtools for React Router - debug, trace, find hydration errors, catch bugs and inspect server/client data with react-router-devtools",
"author": "Alem Tuzlak",
"version": "1.0.3",
"version": "1.0.4",
"license": "MIT",
"keywords": [
"react-router",
Expand Down
15 changes: 7 additions & 8 deletions src/vite/editor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { exec } from "node:child_process"
import fs from "node:fs"
import path from "node:path"
import { normalizePath } from "vite"
import { checkPath } from "./utils.js"

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

export const DEFAULT_EDITOR_CONFIG: EditorConfig = {
name: "VSCode",
open: (path, lineNumber) => {
open: async (path, lineNumber) => {
const { exec } = await import("node:child_process")
exec(`code -g "${normalizePath(path).replaceAll("$", "\\$")}${lineNumber ? `:${lineNumber}` : ""}"`)
},
}

export const handleOpenSource = ({
export const handleOpenSource = async ({
data,
openInEditor,
appDir,
}: {
data: OpenSourceData
appDir: string
openInEditor: (path: string, lineNum: string | undefined) => void
openInEditor: (path: string, lineNum: string | undefined) => Promise<void>
}) => {
const { source, line, routeID } = data.data
const lineNum = line ? `${line}` : undefined

const fs = await import("node:fs")
const path = await import("node:path")
if (source) {
return openInEditor(source, lineNum)
}

if (routeID) {
const routePath = path.join(appDir, routeID)
const checkedPath = checkPath(routePath)
const checkedPath = await checkPath(routePath)

if (!checkedPath) return
const { type, validPath } = checkedPath
Expand Down
2 changes: 1 addition & 1 deletion src/vite/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
)
})
const editor = args?.editor ?? DEFAULT_EDITOR_CONFIG
const openInEditor = (path: string | undefined, lineNum: string | undefined) => {
const openInEditor = async (path: string | undefined, lineNum: string | undefined) => {
if (!path) {
return
}
Expand Down
4 changes: 2 additions & 2 deletions src/vite/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fs from "node:fs"
import type { IncomingMessage, ServerResponse } from "node:http"
import type { Connect } from "vite"

Expand Down Expand Up @@ -49,7 +48,8 @@ export const handleDevToolsViteRequest = (
})
}

export function checkPath(routePath: string, extensions = [".tsx", ".jsx", ".ts", ".js"]) {
export async function checkPath(routePath: string, extensions = [".tsx", ".jsx", ".ts", ".js"]) {
const fs = await import("node:fs")
// Check if the path exists as a directory
if (fs.existsSync(routePath) && fs.lstatSync(routePath).isDirectory()) {
return { validPath: routePath, type: "directory" } as const
Expand Down
2 changes: 1 addition & 1 deletion test-apps/react-router-vite/app/routes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

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

0 comments on commit be6d265

Please sign in to comment.