Skip to content

Commit f59cf14

Browse files
authored
Feat/migrate to tanstack devtools (#236)
* tanstack migration init * remove tailwind for goober * update deps * migrate to event client * make ui look much nicer on event tab * better ui * improve events screen * swap to evenets for server info * removed custom behavior and rely on tanstack devtools for open source and uses event client for route info * removed detached mode * remove hydration diff detector * remove errors tab * remove bippy * add middleware logs and events * fix bugs * update ui * ui improvements * remove settings tab * remove settings tab * cleanup of old code * add back in plugins and cleanup package exports * improve ui and logs * update docs * fix * docs(changeset): migrated to TanStack Devtools * changeset * add license * fix bugs * fix bugs * fix bugs * update docs for data mode * update styles
1 parent 82c096a commit f59cf14

File tree

169 files changed

+8754
-9414
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

169 files changed

+8754
-9414
lines changed

.changeset/mean-facts-swim.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
"react-router-devtools": major
3+
---
4+
5+
Migration to TanStack Devtools is here! 🎉
6+
7+
You can now leverage the powerful features of TanStack Devtools within React Router Devtools, enhancing your debugging and development experience.
8+
9+
You can easily create your own devtool plugins, inspect application state, and trace network requests with improved visibility.
10+
11+
### Key Changes:
12+
- **TanStack Integration**: Seamless integration with TanStack Devtools for advanced debugging capabilities
13+
- **Enhanced UI**: New panels and tabs for better state and network inspection
14+
- **Improved Performance**: Optimized for faster load times and reduced overhead
15+
- **Middleware Support**: Ability to log middleware events and actions for deeper insights and also see them on the network tab
16+
- **Extended Configuration**: New configuration options to customize TanStack Devtools behavior alongside React Router
17+
18+
### Migration Steps:
19+
1. Update your configuration to include TanStack-specific options.
20+
2. Review and adjust any custom plugins to ensure compatibility with the new TanStack integration.
21+
3. Test your application to verify that all devtools features are functioning as expected.
22+
23+
### Features that have been removed:
24+
- The route creation via devtools UI has been removed.
25+
- Server info on the active page tab has been removed.

.github/copilot-instructions.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
applyTo: '**'
3+
---
4+
Provide project context and coding guidelines that AI should follow when generating code, answering questions, or reviewing changes.
5+
6+
Whenever you want to build the packages to test if they work you should run `pnpm run build` from the root of the repository.
7+
8+
If you want to run tests you can run `pnpm run test` from the root of the repository.
9+
10+
If you want to check if the examples work you need to go to `test-apps/<example-name>` and run `pnpm run dev`.
11+
12+
When writing code, please follow these guidelines:
13+
- Use TypeScript for all new code.
14+
- Ensure all new code is covered by tests.
15+
- Do not use `any` type; prefer specific types or generics.
16+
- Follow existing code style and conventions.
17+
18+
If you get an error "address already in use :::42069 you should kill the process using that port.
19+
20+
If we add a new functionality add a section about it in the `docs/content` folder explaining how to use it and update the `README.md` file to mention it.
21+
22+
Write tests for any new functionality.
23+
24+
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.
25+
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.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Forge 42
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +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",
68-
"@bkrem/react-transition-group",
6965
],
7066
},
7167
```

docs/app/routes/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import { Meteors } from "~/components/ui/Meteors"
77
import { InfiniteMovingCards } from "~/components/ui/infinite-cards"
88
import { Navbar } from "~/components/ui/navbar-menu"
99
import { TypewriterEffect } from "~/components/ui/typewritter"
10-
import { Route } from "./+types"
11-
import { buildDocPathFromSlug } from "~/utils/path-builders"
10+
import type { Route } from "./+types"
1211
import { generateMetaFields } from "~/utils/seo"
1312
import { getDomain } from "~/utils/get-domain"
1413

@@ -97,7 +96,7 @@ export function OpenSourceReveal() {
9796
}
9897
className="h-[40rem]"
9998
>
100-
Click <span className="text-red-500">Shift + Right Click</span> to directly go to element source in
99+
Click <span className="text-red-500">Shift + Ctrl + Left Click</span> to directly go to element source in
101100
<span className="ml-2 text-blue-500">VS Code</span> 🔥
102101
</MaskContainer>
103102
</div>

docs/content/01-started/01-installation.mdx

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ npm install react-router-devtools -D
1414

1515
This will install it as a dev dependency in your project.
1616

17-
## Enabling the tools
17+
## Enabling the tools (framework mode)
1818

1919
After you have installed the tools, you need to go to your `vite.config.ts` file which will probably look something like this:
2020

@@ -47,17 +47,43 @@ export default defineConfig({
4747
Make sure your plugin is BEFORE the react router one!
4848
</WarningAlert>
4949

50+
51+
## Enabling the tools (data/declarative mode)
52+
53+
If you are using React Router in data/declarative mode, you can still use the devtools
54+
by first installing @tanstack/react-devtools and then adding the devtools somewhere under
55+
the router provider in your app.
56+
57+
```tsx
58+
import { TanStackDevtools } from '@tanstack/react-devtools';
59+
import { EmbeddedDevTools } from 'react-router-devtools';
60+
61+
export function App() {
62+
return (
63+
<>
64+
<YourRouterProvider>
65+
<YourAppComponents />
66+
<TanStackDevtools plugins=[{
67+
name: "React Router",
68+
render: <EmbeddedDevTools />
69+
}] />
70+
</YourRouterProvider>
71+
<TanStackDevtools />
72+
</>
73+
);
74+
}
75+
```
76+
77+
react-router-devtools uses @tanstack/devtools as the base for the UI, you can refer to their
78+
[documentation](https://tanstack.com/devtools/latest/docs/overview) for more information on how to use the devtools interface.
79+
5080
### CloudFlare
5181

5282
If you're trying to spin it up on CF, try adding this to your `optimizeDeps` in your `vite.config.js` file:
5383
```ts
5484
optimizeDeps: {
5585
include: [
5686
// other optimized deps
57-
"beautify",
58-
"react-diff-viewer-continued",
59-
"classnames",
60-
"@bkrem/react-transition-group",
6187
],
6288
},
6389
```

docs/content/02-features/02-active-page-tab.mdx renamed to docs/content/02-features/01-active-page-tab.mdx

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ gradient background that can be set in the settings.
1616
<InfoAlert>
1717
This feature is only available in the development mode because it used react dev tools to find the `<Outlet />` component.
1818

19-
If you want to try it open up the dev tools right now nad hover over `/docs/main` in the panel.
20-
21-
You can also change the gradient background color in the settings.
2219
</InfoAlert>
2320

2421
## Loader list
@@ -33,16 +30,6 @@ the loader type and the loader file.
3330
- `green` - represents a normal route file, whether index or not
3431
</InfoAlert>
3532

36-
### Open in VS code
37-
38-
Each segment has an **open in VS code** button that opens the loader file in VS code.
39-
This is useful for quick navigation to the loader file.
40-
41-
<InfoAlert title="Caveat!">
42-
This only works if you have the `code` command installed in your terminal. If you don't have it installed you can
43-
install it by following the instructions [here](https://code.visualstudio.com/docs/setup/mac#_launching-from-the-command-line).
44-
</InfoAlert>
45-
4633
### Loader data
4734

4835
Each segment has a loader data **JSON** object that contains all the information returned by the loader of that segment.
@@ -66,19 +53,6 @@ This will contain all the **wildcard** params currently available on this route.
6653
If you open up the dev tools, you will be able to see that `tag` and `slug` are both in
6754
the route params.
6855

69-
### Server info
70-
71-
The server info section contains all the server information for the current segment, including:
72-
- `loaderTriggerCount` - the number of times the loader has been triggered (updates in real-time)
73-
- `actionTriggerCount` - the number of times the action has been triggered (updates in real-time)
74-
- `lowestExecutionTime` - the lowest execution time of the loader (updates in real-time)
75-
- `highestExecutionTime` - the highest execution time of the loader (updates in real-time)
76-
- `averageExecutionTime` - the average execution time of the loader (updates in real-time)
77-
- `lastLoaderInfo` - the last loader info object (updates in real-time), includes execution time, request headers and response headers.
78-
- `lastActionInfo` - the last action info object (updates in real-time), includes execution time, request headers and response headers.
79-
- `loaderCalls` - an array of loaderInfo objects ordered from most recent to least recent (updates in real-time)
80-
- `actionCalls` - an array of actionInfo objects ordered from most recent to least recent (updates in real-time)
81-
8256
### handles
8357

8458
The handles section contains all the handles for the current segment.
@@ -98,7 +72,7 @@ The timeline section on the right contains useful information on navigation and
9872

9973
Every time there is a navigation or submission event, a new entry will be added to the timeline on the top.
10074

101-
It is limited to 50 entries and will remove the oldest entry when the limit is reached.
75+
It is limited to 30 entries and will remove the oldest entry when the limit is reached.
10276

10377
The timeline will contain the following information for each event:
10478
- `type` - the type of event (navigation or submission, fetcher or normal)

docs/content/02-features/01-shortcuts.mdx

Lines changed: 0 additions & 28 deletions
This file was deleted.
File renamed without changes.

docs/content/02-features/07-devtools.mdx renamed to docs/content/02-features/03-devtools.mdx

Lines changed: 25 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ summary: "The Devtools context provides tracing utilities for loaders and action
44
description: "Using the devtools context to trace events and send them to the network tab"
55
---
66

7+
## TanStack DevTools Integration
8+
9+
React Router Devtools v6+ integrates with [TanStack DevTools](https://tanstack.com/devtools), providing enhanced debugging capabilities alongside React Router specific features. The devtools now include:
10+
11+
- React Router specific tabs (Active Page, Routes, Network, Timeline, Settings)
12+
- TanStack DevTools panels for advanced state inspection
13+
- Unified debugging experience with seamless integration
14+
15+
You can configure TanStack-specific behavior through the [general configuration](/configuration/general#tanstack-devtools-integration).
16+
17+
---
718

819
## Devtools extended context
920

@@ -19,9 +30,9 @@ export const loader = async ({ request, devTools }: LoaderFunctionArgs) => {
1930
const tracing = devTools?.tracing;
2031
// tracing is a set of utilities to be used in your data fetching functions to trace events
2132
// in network tab of react-router-devtools
22-
const startTime = tracing.start("my-event")
33+
const end = tracing.start("my-event")
2334
// do something here, eg DB call
24-
tracing.end("my-event", startTime!)
35+
end()
2536
return "data"
2637
}
2738
```
@@ -33,9 +44,9 @@ export const action = async ({ request, devTools }: ActionFunctionArgs) => {
3344
const tracing = devTools?.tracing;
3445
// tracing is a set of utilities to be used in your data fetching functions to trace events
3546
// in network tab of react-router-devtools
36-
const startTime = tracing?.start("my-event")
47+
const end = tracing?.start("my-event")
3748
// do something
38-
tracing?.end("my-event", startTime!)
49+
end()
3950
return "data"
4051
}
4152
```
@@ -47,9 +58,9 @@ export const clientLoader = async ({ request, devTools }: ClientLoaderFunctionAr
4758
const tracing = devTools?.tracing;
4859
// tracing is a set of utilities to be used in your data fetching functions to trace events
4960
// in network tab of react-router-devtools
50-
const startTime = tracing?.start("my-event")
61+
const end = tracing?.start("my-event")
5162
// do something
52-
tracing?.end("my-event", startTime!)
63+
end()
5364
return "data"
5465
}
5566
```
@@ -59,9 +70,9 @@ export const clientAction = async ({ request, devTools }: ClientActionFunctionAr
5970
const tracing = devTools?.tracing;
6071
// tracing is a set of utilities to be used in your data fetching functions to trace events
6172
// in network tab of react-router-devtools
62-
const startTime = tracing?.start("my-event")
73+
const end = tracing?.start("my-event")
6374
// do something
64-
tracing?.end("my-event", startTime!)
75+
end()
6576
return "data"
6677
}
6778
```
@@ -103,10 +114,9 @@ const loader = async ({ request, devTools }: LoaderFunctionArgs) => {
103114
The tracing object contains all the utilities related to network tab tracing feature of react-router-devtools.
104115

105116

106-
There are three functions you can use:
117+
There are two functions you can use:
107118
- trace
108119
- start
109-
- end
110120

111121

112122

@@ -143,18 +153,18 @@ This is used together with `end` to trace the time of the event.
143153
export const loader = async ({ request, devTools }: LoaderFunctionArgs) => {
144154
const tracing = devTools?.tracing;
145155
// this will be traced in the network tab of react-router-devtools
146-
const startTime = tracing?.start("my-event")
156+
const end = tracing?.start("my-event")
147157
// do something here, eg DB call
148158

149159
// End the trace
150-
tracing?.end("my-event", startTime!)
160+
end()
151161
return "data"
152162
}
153163
```
154164

155165
<WarningAlert title="Warning">
156-
This function relies on you using the `end` with the same name as the start event, otherwise
157-
you will end up having a never ending loading bar in the network tab!
166+
This function relies on you using the `end`returned from it, otherwise the event
167+
will never end in your devtools
158168
</WarningAlert>
159169

160170

@@ -164,32 +174,4 @@ you will end up having a never ending loading bar in the network tab!
164174

165175
#### Returns
166176

167-
The start time of the event
168-
169-
### end
170-
171-
The `end` function is a function that will end a trace for the name provided to it and return the end time.
172-
173-
```ts
174-
export const loader = async ({ request, devTools }: LoaderFunctionArgs) => {
175-
const tracing = devTools?.tracing;
176-
// this will be traced in the network tab of react-router-devtools
177-
const startTime = tracing?.start("get user")
178-
// do something here, eg DB call
179-
const user = await getUser();
180-
// End the trace
181-
tracing?.end("get user", startTime!, { user })
182-
return "data"
183-
184-
}
185-
```
186-
187-
#### Parameters
188-
189-
- `name` - The name of the event
190-
- `startTime` - The start time of the sendEvent
191-
- `data` - The data to be sent with the event
192-
193-
#### Returns
194-
195-
The data provided in the last parameter
177+
The end trace function

0 commit comments

Comments
 (0)