Skip to content

Commit 99f38c4

Browse files
authored
77 active page tab stuck once popping rdt out into new window (#80)
* #77 - Detached mode location tracking fix * action color change
1 parent 1f3045d commit 99f38c4

32 files changed

+834
-38
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "remix-development-tools",
33
"description": "Remix development tools - a set of tools for developing/debugging Remix.run apps",
44
"author": "Alem Tuzlak",
5-
"version": "3.5.0",
5+
"version": "3.5.1",
66
"license": "MIT",
77
"keywords": [
88
"remix",

src/RemixDevTools/RemixDevTools.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { useOpenElementSource } from "./hooks/useOpenElementSource.js";
2525
import { RdtPlugin } from "../client.js";
2626
import { useAttachBodyListener } from "./hooks/useAttachListener.js";
2727
import { useDebounce } from "./hooks/useDebounce.js";
28+
import { useListenToRouteChange } from "./hooks/detached/useListenToRouteChange.js";
2829

2930
const DevTools = ({ plugins: pluginArray }: RemixDevToolsProps) => {
3031
useTimelineHandler();
@@ -34,7 +35,7 @@ const DevTools = ({ plugins: pluginArray }: RemixDevToolsProps) => {
3435
useSyncStateWhenDetached();
3536
useDevServerConnection();
3637
useOpenElementSource();
37-
38+
useListenToRouteChange();
3839
const url = useLocation().search;
3940
const { detachedWindowOwner, isDetached, setDetachedWindowOwner } = useDetachedWindowControls();
4041
const { settings } = useSettingsContext();

src/RemixDevTools/context/RDTContext.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { Dispatch } from "react";
22
import React, { useMemo, createContext, useReducer, useEffect } from "react";
33
import { RemixDevToolsActions, RemixDevToolsState, rdtReducer, initialState } from "./rdtReducer.js";
44
import { useRemoveBody } from "../hooks/detached/useRemoveBody.js";
5-
import { useListenToRouteChange } from "../hooks/detached/useListenToRouteChange.js";
65
import {
76
setSessionItem,
87
setStorageItem,
@@ -84,7 +83,7 @@ export const getExistingStateFromStorage = () => {
8483
export const RDTContextProvider = ({ children }: ContextProps) => {
8584
const [state, dispatch] = useReducer<typeof rdtReducer>(rdtReducer, getExistingStateFromStorage());
8685
const value = useMemo(() => ({ state, dispatch }), [state, dispatch]);
87-
useListenToRouteChange();
86+
8887
useRemoveBody(state);
8988

9089
useEffect(() => {

src/RemixDevTools/context/rdtReducer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { TimelineEvent } from "./timeline/types.js";
22
import type { Tabs } from "../tabs/index.js";
33
import { Terminal } from "./terminal/types.js";
44
import { ActionEvent, LoaderEvent } from "../../dev-server/event-queue.js";
5-
import { cutArrayToLastN } from "../utils/common.js";
5+
import { cutArrayToFirstN } from "../utils/common.js";
66

77
export const defaultServerRouteState: ServerRouteInfo = {
88
highestExecutionTime: 0,
@@ -268,7 +268,7 @@ export const rdtReducer = (
268268
case "SET_TIMELINE_EVENT":
269269
return {
270270
...state,
271-
timeline: cutArrayToLastN([payload, ...state.timeline], 30),
271+
timeline: cutArrayToFirstN([payload, ...state.timeline], 30),
272272
};
273273

274274
case "SET_WHOLE_STATE": {

src/RemixDevTools/hooks/detached/useListenToRouteChange.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { useLocation, useNavigate, useNavigation } from "@remix-run/react";
22
import { useEffect, useRef } from "react";
3-
import { useAttachListener } from '../useAttachListener.js';
4-
import { getStorageItem, setStorageItem } from '../../utils/storage.js';
5-
import { useDetachedWindowControls } from '../../context/useRDTContext.js';
3+
import { useAttachListener } from "../useAttachListener.js";
4+
import { getStorageItem, setStorageItem } from "../../utils/storage.js";
5+
import { useDetachedWindowControls } from "../../context/useRDTContext.js";
6+
import { detachedModeSetup } from "../../context/RDTContext.js";
67

78
export const LOCAL_STORAGE_ROUTE_KEY = "rdt_route";
89

@@ -22,8 +23,12 @@ export const useListenToRouteChange = () => {
2223

2324
// Used by the owner window only
2425
useEffect(() => {
26+
const { detachedWindowOwner } = detachedModeSetup();
27+
if (!detachedWindowOwner) {
28+
return;
29+
}
2530
// If the route changes and this is the original window store the event into local storage
26-
if (route !== locationRoute && detachedWindowOwner) {
31+
if (route !== locationRoute) {
2732
setRouteInLocalStorage(locationRoute);
2833
}
2934
}, [locationRoute, detachedWindowOwner, route]);

src/RemixDevTools/utils/common.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@ export const cutArrayToLastN = <T>(arr: T[], n: number) => {
22
if (arr.length < n) return arr;
33
return arr.slice(arr.length - n);
44
};
5+
6+
export const cutArrayToFirstN = <T>(arr: T[], n: number) => {
7+
if (arr.length < n) return arr;
8+
return arr.slice(0, n);
9+
};

src/dev-server/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const actionLog = (message: string) => {
3737
if (config.logs?.actions === false) {
3838
return;
3939
}
40-
log(`${chalk.red.bold("ACTION")} ${message}`);
40+
log(`${chalk.yellowBright.bold("ACTION")} ${message}`);
4141
};
4242

4343
export const successLog = (message: string) => {

src/dev-server/utils.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,16 @@ const logTrigger = (id: string, type: "action" | "loader", end: number) => {
135135
}
136136
};
137137

138-
const extractHeadersFromResponseOrRequest = (response: Response | Request): Record<string, string> => {
138+
const extractHeadersFromResponseOrRequest = (response: Response | Request) => {
139139
const headers = new Headers(response.headers);
140140
return Object.fromEntries(headers.entries());
141141
};
142142

143143
const extractDataFromResponseOrRequest = async (response: Response | Request): Promise<null | unknown> => {
144-
const extractable = new Response(response.body, response)
145-
const headers = new Headers(extractable.headers);
146-
const contentType = headers.get("Content-Type");
147144
try {
145+
const extractable = new Response(response.body, response);
146+
const headers = new Headers(extractable.headers);
147+
const contentType = headers.get("Content-Type");
148148
if (contentType?.includes("application/json")) {
149149
return extractable.json();
150150
}
@@ -170,16 +170,17 @@ const storeAndEmitActionOrLoaderInfo = async (
170170
) => {
171171
const isResponse = response instanceof Response;
172172
const responseHeaders = isResponse ? extractHeadersFromResponseOrRequest(response) : null;
173+
const requestHeaders = extractHeadersFromResponseOrRequest(args.request);
173174
// create the event
174175
const event = {
175176
type,
176177
data: {
177178
id: route.id,
178179
executionTime: end,
179180
timestamp: new Date().getTime(),
180-
responseHeaders,
181-
requestHeaders: extractHeadersFromResponseOrRequest(args.request),
182181
requestData: await extractDataFromResponseOrRequest(args.request),
182+
requestHeaders,
183+
responseHeaders,
183184
},
184185
};
185186
const port =
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { ReactNode } from "react";
2+
3+
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
4+
children: ReactNode
5+
}
6+
7+
const Button = ({ children, ...props }: ButtonProps) => {
8+
return (
9+
<button {...props}>
10+
{children}
11+
</button>
12+
);
13+
}
14+
15+
export { Button };

src/test-apps/remix-vite/app/root.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default function App() {
3131
</head>
3232
<body>
3333
<Form method="post">
34-
34+
<input readOnly type="text" name="name" value={"name"} />
3535
<button type="submit">
3636
Submit
3737
</button>

0 commit comments

Comments
 (0)