Skip to content

Commit 8ec73ce

Browse files
committed
removed detached mode
1 parent 13f36fb commit 8ec73ce

File tree

6 files changed

+4
-124
lines changed

6 files changed

+4
-124
lines changed

packages/react-router-devtools/src/client/context/RDTContext.test.tsx

Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
import { render } from "@testing-library/react"
2-
import * as detachedMethods from "../utils/detached.js"
3-
import {
4-
REACT_ROUTER_DEV_TOOLS_CHECK_DETACHED,
5-
REACT_ROUTER_DEV_TOOLS_DETACHED,
6-
REACT_ROUTER_DEV_TOOLS_SETTINGS,
7-
REACT_ROUTER_DEV_TOOLS_STATE,
8-
} from "../utils/storage.js"
9-
import {
10-
RDTContextProvider,
11-
//detachedModeSetup,
12-
getSettings,
13-
resetIsDetachedCheck,
14-
setIsDetachedIfRequired,
15-
//getExistingStateFromStorage,
16-
} from "./RDTContext.js"
2+
import { REACT_ROUTER_DEV_TOOLS_SETTINGS, REACT_ROUTER_DEV_TOOLS_STATE } from "../utils/storage.js"
3+
import { RDTContextProvider, getSettings } from "./RDTContext.js"
174

185
vi.mock("react-router", () => ({
196
useLocation: () => ({
@@ -85,51 +72,3 @@ describe("getSettings", () => {
8572
expect(settings).toEqual(storedSettings)
8673
})
8774
})
88-
89-
describe("setIsDetachedIfRequired", () => {
90-
it('should set REACT_ROUTER_DEV_TOOLS_DETACHED to "true" if window is not detached but RDT_MOUNTED is true', () => {
91-
const isDetachedWindowSpy = vi.spyOn(detachedMethods, "checkIsDetachedWindow").mockReturnValue(false)
92-
const setSessionSpy = vi.spyOn(sessionStorage, "setItem")
93-
const window = { RDT_MOUNTED: true }
94-
95-
// biome-ignore lint/suspicious/noExplicitAny: test
96-
;(global as any).window = window
97-
setIsDetachedIfRequired()
98-
expect(isDetachedWindowSpy).toHaveBeenCalled()
99-
expect(setSessionSpy).toHaveBeenCalledWith(REACT_ROUTER_DEV_TOOLS_DETACHED, "true")
100-
})
101-
102-
it("should not set REACT_ROUTER_DEV_TOOLS_DETACHED if window is detached", () => {
103-
const isDetachedWindowSpy = vi.spyOn(detachedMethods, "checkIsDetachedWindow").mockReturnValue(true)
104-
const setSessionSpy = vi.spyOn(sessionStorage, "setItem")
105-
const window = { RDT_MOUNTED: false }
106-
107-
// biome-ignore lint/suspicious/noExplicitAny: test
108-
;(global as any).window = window
109-
110-
setIsDetachedIfRequired()
111-
expect(isDetachedWindowSpy).toHaveBeenCalled()
112-
expect(setSessionSpy).not.toHaveBeenCalled()
113-
})
114-
115-
it("should not set REACT_ROUTER_DEV_TOOLS_DETACHED if RDT_MOUNTED is false && isDetachedWindow is false", () => {
116-
const isDetachedWindowSpy = vi.spyOn(detachedMethods, "checkIsDetachedWindow").mockReturnValue(false)
117-
const setSessionSpy = vi.spyOn(sessionStorage, "setItem")
118-
const window = { RDT_MOUNTED: false }
119-
// biome-ignore lint/suspicious/noExplicitAny: test
120-
;(global as any).window = window
121-
122-
setIsDetachedIfRequired()
123-
expect(isDetachedWindowSpy).toHaveBeenCalled()
124-
expect(setSessionSpy).not.toHaveBeenCalled()
125-
})
126-
})
127-
128-
describe("resetIsDetachedCheck", () => {
129-
it('should set REACT_ROUTER_DEV_TOOLS_CHECK_DETACHED to "false" whenever the window is mounted', () => {
130-
const setStorageSpy = vi.spyOn(localStorage, "setItem")
131-
132-
resetIsDetachedCheck()
133-
expect(setStorageSpy).toHaveBeenCalledWith(REACT_ROUTER_DEV_TOOLS_CHECK_DETACHED, "false")
134-
})
135-
})

packages/react-router-devtools/src/client/context/RDTContext.tsx

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@ import type { Dispatch } from "react"
22
import type React from "react"
33
import { createContext, useEffect, useMemo, useReducer } from "react"
44
import { bigIntReplacer } from "../../shared/bigint-util.js"
5-
import { checkIsDetached, checkIsDetachedOwner, checkIsDetachedWindow } from "../utils/detached.js"
65
import { tryParseJson } from "../utils/sanitize.js"
76
import {
8-
REACT_ROUTER_DEV_TOOLS_CHECK_DETACHED,
9-
REACT_ROUTER_DEV_TOOLS_DETACHED,
107
REACT_ROUTER_DEV_TOOLS_SETTINGS,
118
REACT_ROUTER_DEV_TOOLS_STATE,
129
getStorageItem,
13-
setSessionItem,
1410
setStorageItem,
1511
} from "../utils/storage.js"
1612
import {
@@ -32,37 +28,6 @@ interface ContextProps {
3228
config?: RdtClientConfig
3329
}
3430

35-
export const setIsDetachedIfRequired = () => {
36-
const isDetachedWindow = checkIsDetachedWindow()
37-
if (!isDetachedWindow && window.RDT_MOUNTED) {
38-
setSessionItem(REACT_ROUTER_DEV_TOOLS_DETACHED, "true")
39-
}
40-
}
41-
42-
export const resetIsDetachedCheck = () => {
43-
setStorageItem(REACT_ROUTER_DEV_TOOLS_CHECK_DETACHED, "false")
44-
}
45-
46-
export const detachedModeSetup = () => {
47-
resetIsDetachedCheck()
48-
setIsDetachedIfRequired()
49-
const isDetachedWindow = checkIsDetachedWindow()
50-
const isDetached = checkIsDetached()
51-
const isDetachedOwner = checkIsDetachedOwner()
52-
53-
if (isDetachedWindow && !isDetached) {
54-
window.close()
55-
}
56-
if (!isDetached && isDetachedOwner) {
57-
//setSessionItem(REMIX_DEV_TOOLS_DETACHED_OWNER, "false");
58-
// isDetachedOwner = false;
59-
}
60-
return {
61-
detachedWindow: window.RDT_MOUNTED ?? isDetachedWindow,
62-
detachedWindowOwner: isDetachedOwner,
63-
}
64-
}
65-
6631
export const getSettings = () => {
6732
const settingsString = getStorageItem(REACT_ROUTER_DEV_TOOLS_SETTINGS)
6833
const settings = tryParseJson<ReactRouterDevtoolsState["settings"]>(settingsString)
@@ -75,7 +40,6 @@ export const getExistingStateFromStorage = (config?: RdtClientConfig & { editorN
7540
const existingState = getStorageItem(REACT_ROUTER_DEV_TOOLS_STATE)
7641
const settings = getSettings()
7742

78-
const { detachedWindow, detachedWindowOwner } = detachedModeSetup()
7943
const state: ReactRouterDevtoolsState = {
8044
...initialState,
8145
...(existingState ? JSON.parse(existingState) : {}),
@@ -85,8 +49,6 @@ export const getExistingStateFromStorage = (config?: RdtClientConfig & { editorN
8549
...settings,
8650
editorName: config?.editorName ?? initialState.settings.editorName,
8751
},
88-
detachedWindow,
89-
detachedWindowOwner,
9052
}
9153
return state
9254
}

packages/react-router-devtools/src/client/context/rdtReducer.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,6 @@ type SetTimelineEvent = {
118118
payload: TimelineEvent
119119
}
120120

121-
type SetDetachedWindowOwner = {
122-
type: "SET_DETACHED_WINDOW_OWNER"
123-
payload: boolean
124-
}
125-
126121
type SetWholeState = {
127122
type: "SET_WHOLE_STATE"
128123
payload: ReactRouterDevtoolsState
@@ -165,7 +160,6 @@ export type ReactRouterDevtoolsActions =
165160
| PurgeTimeline
166161
| SetSettings
167162
| SetWholeState
168-
| SetDetachedWindowOwner
169163
| SetIsSubmittedAction
170164
| SetServerInfo
171165
| SetHtmlErrors

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const useSetRouteBoundaries = () => {
4040
},
4141
[settings.hoveredRoute, settings.isHoveringRoute, settings.routeBoundaryGradient, matches.length, styles.gradients]
4242
)
43-
// Mouse left the document => remove classes => set isHovering to false so that detached mode removes as well
43+
// Mouse left the document => remove classes => set isHovering to false
4444
useAttachListener("mouseleave", "document", () => {
4545
if (settings.showRouteBoundariesOn === "click") {
4646
return
@@ -51,7 +51,7 @@ export const useSetRouteBoundaries = () => {
5151
isHoveringRoute: false,
5252
})
5353
})
54-
// Mouse is scrolling => remove classes => set isHovering to false so that detached mode removes as well
54+
// Mouse is scrolling => remove classes => set isHovering to false
5555
useAttachListener("wheel", "window", () => {
5656
if (settings.showRouteBoundariesOn === "click") {
5757
return

packages/react-router-devtools/src/client/utils/detached.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/react-router-devtools/src/client/utils/storage.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,3 @@ export const getBooleanFromSession = (key: string) => getSessionItem(key) === "t
2121
export const REACT_ROUTER_DEV_TOOLS = "react_router_devtools"
2222
export const REACT_ROUTER_DEV_TOOLS_STATE = "react_router_devtools_state"
2323
export const REACT_ROUTER_DEV_TOOLS_SETTINGS = "react_router_devtools_settings"
24-
export const REACT_ROUTER_DEV_TOOLS_DETACHED = "react_router_devtools_detached"
25-
export const REACT_ROUTER_DEV_TOOLS_DETACHED_OWNER = "react_router_devtools_detached_owner"
26-
export const REACT_ROUTER_DEV_TOOLS_IS_DETACHED = "react_router_devtools_is_detached"
27-
export const REACT_ROUTER_DEV_TOOLS_CHECK_DETACHED = "react_router_devtools_check_detached"

0 commit comments

Comments
 (0)