Skip to content

Commit 2d40822

Browse files
committed
add back in plugins and cleanup package exports
1 parent b40cc6d commit 2d40822

File tree

27 files changed

+568
-1477
lines changed

27 files changed

+568
-1477
lines changed

.github/copilot-instructions.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ Write tests for any new functionality.
2323

2424
When defining new types, first check if the types exist somewhere and re-use them, do not create new types that are similar to existing ones.
2525

26-
When modifying existing functionality, ensure backward compatibility unless there's a strong reason to introduce breaking changes. If breaking changes are necessary, document them clearly in the relevant documentation files.
26+
When modifying existing functionality, ensure backward compatibility unless there's a strong reason to introduce breaking changes. If breaking changes are necessary, document them clearly in the relevant documentation files.
27+
28+
If `pnpm run test` fails because of check, you can run `pnpm run check:fix` to fix the issues automatically.

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ If you're trying to spin it up on CF, try adding this to your `optimizeDeps` in
6262
optimizeDeps: {
6363
include: [
6464
// other optimized deps
65-
"beautify",
66-
"react-diff-viewer-continued",
67-
"classnames",
6865
"@bkrem/react-transition-group",
6966
],
7067
},

packages/react-router-devtools/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@
5353
},
5454
"types": "./dist/server.d.ts",
5555
"default": "./dist/server.js"
56-
},
57-
"./client.css": {
58-
"import": "./dist/client.css",
59-
"require": "./dist/client.css"
6056
}
6157
},
6258
"files": ["dist"],
@@ -109,6 +105,7 @@
109105
"@react-router/dev": "7.9.3",
110106
"@react-router/node": "7.9.3",
111107
"@react-router/serve": "7.9.3",
108+
"@tanstack/devtools": "^0.8.1",
112109
"@testing-library/dom": "^10.4.0",
113110
"@testing-library/react": "16.2.0",
114111
"@types/babel__core": "^7.20.5",

packages/react-router-devtools/src/client/embedded-dev-tools.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import clsx from "clsx"
22
import { useEffect, useState } from "react"
33
import { RDTContextProvider } from "./context/RDTContext.js"
4-
import { useReactTreeListeners } from "./hooks/useReactTreeListeners.js"
4+
import { useFindRouteOutlets } from "./hooks/useReactTreeListeners.js"
55
import { useSetRouteBoundaries } from "./hooks/useSetRouteBoundaries.js"
66
import { useTimelineHandler } from "./hooks/useTimelineHandler.js"
77
import { ContentPanel } from "./layout/ContentPanel.js"
@@ -17,13 +17,11 @@ export interface EmbeddedDevToolsProps extends ReactRouterDevtoolsProps {
1717
mainPanelClassName?: string
1818
className?: string
1919
}
20-
const Embedded = ({ plugins: pluginArray, mainPanelClassName, className }: EmbeddedDevToolsProps) => {
20+
const Embedded = ({ mainPanelClassName, className }: EmbeddedDevToolsProps) => {
2121
useTimelineHandler()
22-
useReactTreeListeners()
22+
useFindRouteOutlets()
2323
useSetRouteBoundaries()
2424

25-
const plugins = pluginArray?.map((plugin) => (typeof plugin === "function" ? plugin() : plugin))
26-
2725
return (
2826
<div
2927
id={REACT_ROUTER_DEV_TOOLS}
@@ -33,8 +31,8 @@ const Embedded = ({ plugins: pluginArray, mainPanelClassName, className }: Embed
3331
className={clsx("react-router-dev-tools", "h-full flex-row w-full", className)}
3432
>
3533
<MainPanel className={mainPanelClassName} isEmbedded isOpen={true}>
36-
<Tabs plugins={plugins} />
37-
<ContentPanel plugins={plugins} />
34+
<Tabs />
35+
<ContentPanel />
3836
</MainPanel>
3937
</div>
4038
)
@@ -53,15 +51,15 @@ function useHydrated() {
5351
return hydrated
5452
}
5553

56-
const EmbeddedDevTools = ({ plugins, mainPanelClassName, className }: EmbeddedDevToolsProps) => {
54+
const EmbeddedDevTools = ({ config, mainPanelClassName, className }: EmbeddedDevToolsProps) => {
5755
const hydrated = useHydrated()
5856

5957
if (!hydrated) return null
6058

6159
return (
62-
<RDTContextProvider>
60+
<RDTContextProvider config={config}>
6361
<RequestProvider>
64-
<Embedded mainPanelClassName={mainPanelClassName} className={className} plugins={plugins} />
62+
<Embedded mainPanelClassName={mainPanelClassName} className={className} />
6563
</RequestProvider>
6664
</RDTContextProvider>
6765
)

packages/react-router-devtools/src/client/hooks/useReactTreeListeners.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useNavigation } from "react-router"
33

44
export const ROUTE_CLASS = "outlet-route"
55

6-
export function useReactTreeListeners() {
6+
export function useFindRouteOutlets() {
77
const navigation = useNavigation()
88

99
// biome-ignore lint/suspicious/noExplicitAny: we don't know the type
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import { useMemo } from "react"
22
import { useSettingsContext } from "../context/useRDTContext.js"
3-
import type { ReactRouterDevtoolsProps } from "../react-router-dev-tools.js"
43
import { type Tab, tabs } from "../tabs/index.js"
54

65
const shouldHideTimeline = (tab: Tab | undefined) => {
76
return tab?.hideTimeline
87
}
98

10-
export const useTabs = (pluginsArray?: ReactRouterDevtoolsProps["plugins"]) => {
9+
export const useTabs = () => {
1110
const { settings } = useSettingsContext()
1211
const { activeTab } = settings
13-
const plugins = pluginsArray?.map((plugin) => (typeof plugin === "function" ? plugin() : plugin))
14-
const allTabs = useMemo(() => [...tabs, ...(plugins ? plugins : [])], [plugins])
12+
const allTabs = tabs
1513

1614
const { Component, hideTimeline } = useMemo(() => {
1715
const tab = allTabs.find((tab) => tab.id === activeTab)
@@ -24,6 +22,5 @@ export const useTabs = (pluginsArray?: ReactRouterDevtoolsProps["plugins"]) => {
2422
allTabs,
2523
hideTimeline,
2624
activeTab,
27-
isPluginTab: !tabs.find((tab) => activeTab === tab.id),
2825
}
2926
}
Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { TanStackDevtools } from "@tanstack/react-devtools"
1+
import type { ClientEventBusConfig, TanStackDevtoolsConfig } from "@tanstack/devtools"
2+
import { TanStackDevtools, type TanStackDevtoolsReactPlugin } from "@tanstack/react-devtools"
23
import { Logo } from "../components/logo.js"
34
import type { RdtClientConfig } from "../context/RDTContext.js"
45
import { EmbeddedDevTools } from "../embedded-dev-tools.js"
5-
import type { ReactRouterDevtoolsProps } from "../react-router-dev-tools.js"
66
import { useStyles } from "../styles/use-styles.js"
77

88
export const defineClientConfig = (config: RdtClientConfig) => config
@@ -12,29 +12,50 @@ export const defineClientConfig = (config: RdtClientConfig) => config
1212
* @description Injects the dev tools into the Vite App, ONLY meant to be used by the package plugin, do not use this yourself!
1313
*/
1414

15-
// biome-ignore lint/suspicious/noExplicitAny: we don't know or care about props type
16-
export const withViteDevTools = (Component: any, _config?: ReactRouterDevtoolsProps) => (props: any) => {
17-
// biome-ignore lint/suspicious/noExplicitAny: we don't care about the type here as we spread it below
18-
function AppWithDevTools(props: any) {
19-
const { styles } = useStyles()
20-
return (
21-
<>
22-
<Component {...props} />
23-
<TanStackDevtools
24-
config={{
25-
customTrigger: (
26-
<div data-testid="react-router-devtools-trigger" className={styles.tanstackTrigger.container}>
27-
<Logo className={styles.tanstackTrigger.logo} />
28-
</div>
29-
),
30-
}}
31-
eventBusConfig={{
32-
connectToServerBus: true,
33-
}}
34-
plugins={[{ name: "React Router Devtools", render: <EmbeddedDevTools /> }]}
35-
/>
36-
</>
37-
)
38-
}
39-
return AppWithDevTools(props)
15+
type ViteDevToolsConfig = {
16+
config?: RdtClientConfig
17+
tanstackConfig?: Partial<Omit<TanStackDevtoolsConfig, "customTrigger">>
18+
plugins?: Array<TanStackDevtoolsReactPlugin>
19+
tanstackClientBusConfig?: Partial<ClientEventBusConfig>
4020
}
21+
22+
export const withViteDevTools =
23+
(
24+
// biome-ignore lint/suspicious/noExplicitAny: we don't know or care about props type
25+
Component: any,
26+
viteConfig?: ViteDevToolsConfig
27+
) =>
28+
// biome-ignore lint/suspicious/noExplicitAny: we don't know or care about props type
29+
(props: any) => {
30+
// Extract config parts
31+
const tanStackDevtoolsConfig = viteConfig?.tanstackConfig
32+
const clientBusConfig = viteConfig?.tanstackClientBusConfig
33+
// biome-ignore lint/suspicious/noExplicitAny: we don't care about the type here as we spread it below
34+
function AppWithDevTools(props: any) {
35+
const { styles } = useStyles()
36+
return (
37+
<>
38+
<Component {...props} />
39+
<TanStackDevtools
40+
config={{
41+
...tanStackDevtoolsConfig,
42+
customTrigger: (
43+
<div data-testid="react-router-devtools-trigger" className={styles.tanstackTrigger.container}>
44+
<Logo className={styles.tanstackTrigger.logo} />
45+
</div>
46+
),
47+
}}
48+
eventBusConfig={{
49+
...clientBusConfig,
50+
connectToServerBus: true,
51+
}}
52+
plugins={[
53+
{ name: "React Router", render: <EmbeddedDevTools />, defaultOpen: true },
54+
...(viteConfig?.plugins || []),
55+
]}
56+
/>
57+
</>
58+
)
59+
}
60+
return AppWithDevTools(props)
61+
}

packages/react-router-devtools/src/client/layout/ContentPanel.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,16 @@ import { useTabs } from "../hooks/useTabs.js"
33
import { cx } from "../styles/use-styles.js"
44
import { useStyles } from "../styles/use-styles.js"
55
import { TimelineTab } from "../tabs/TimelineTab.js"
6-
import type { Tab } from "../tabs/index.js"
76

8-
interface ContentPanelProps {
9-
plugins?: Tab[]
10-
}
11-
12-
const ContentPanel = ({ plugins }: ContentPanelProps) => {
13-
const { Component, hideTimeline, isPluginTab, activeTab } = useTabs(plugins)
7+
const ContentPanel = () => {
8+
const { Component, hideTimeline, activeTab } = useTabs()
149
const { styles } = useStyles()
1510

1611
return (
1712
<div className={styles.layout.contentPanel.container}>
1813
<div
1914
className={cx(
2015
styles.layout.contentPanel.mainContent,
21-
isPluginTab && styles.layout.contentPanel.mainContentUnset,
2216
activeTab === "page" && styles.layout.contentPanel.mainContentPageTab
2317
)}
2418
>

packages/react-router-devtools/src/client/layout/Tabs.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ declare global {
1111
}
1212
}
1313

14-
interface TabsProps {
15-
setIsOpen?: React.Dispatch<React.SetStateAction<boolean>>
16-
plugins?: TabType[]
17-
}
18-
1914
const Tab = ({
2015
tab,
2116
activeTab,
@@ -48,11 +43,11 @@ const Tab = ({
4843
)
4944
}
5045

51-
const Tabs = ({ plugins }: TabsProps) => {
46+
const Tabs = () => {
5247
const { settings } = useSettingsContext()
5348
const { styles } = useStyles()
5449
const { activeTab } = settings
55-
const { visibleTabs } = useTabs(plugins)
50+
const { visibleTabs } = useTabs()
5651
const scrollRef = useHorizontalScroll()
5752

5853
return (
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import type { RdtPlugin } from "../index.js"
21
import type { RdtClientConfig } from "./context/RDTContext.js"
3-
import type { Tab } from "./tabs/index.js"
42

53
export interface ReactRouterDevtoolsProps {
6-
// Additional tabs to add to the dev tools
7-
plugins?: (Tab | RdtPlugin)[]
84
config?: RdtClientConfig
95
}

0 commit comments

Comments
 (0)