Skip to content

Commit 615671c

Browse files
committed
remove bippy
1 parent a64aa8d commit 615671c

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

packages/react-router-devtools/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@
141141
"@tanstack/devtools-vite": "^0.3.11",
142142
"@tanstack/react-devtools": "^0.8.0",
143143
"beautify": "^0.0.8",
144-
"bippy": "^0.3.7",
145144
"chalk": "5.4.1",
146145
"clsx": "2.1.1",
147146
"date-fns": "^4.1.0",
Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { type Fiber, onCommitFiberRoot, traverseFiber } from "bippy"
21
import { useCallback, useEffect } from "react"
32
import { useNavigation } from "react-router"
43

@@ -7,25 +6,42 @@ export const ROUTE_CLASS = "outlet-route"
76
export function useReactTreeListeners() {
87
const navigation = useNavigation()
98

10-
// biome-ignore lint/suspicious/noExplicitAny: we don't know the type
11-
const styleNearestElement = useCallback((fiberNode: Fiber<any> | null) => {
9+
// biome-ignore lint/suspicious/noExplicitAny: we don't know the type
10+
const traverseComponentTree = useCallback((fiberNode: any, callback: any) => {
11+
callback(fiberNode)
12+
13+
let child = fiberNode.child
14+
while (child) {
15+
traverseComponentTree(child, callback)
16+
child = child.sibling
17+
}
18+
}, [])
19+
20+
// biome-ignore lint/suspicious/noExplicitAny: we don't know the type
21+
const styleNearestElement = useCallback((fiberNode: any) => {
1222
if (!fiberNode) return
1323

1424
if (fiberNode.stateNode) {
15-
return fiberNode.stateNode?.classList?.add(ROUTE_CLASS)
25+
return fiberNode.stateNode.classList.add(ROUTE_CLASS)
1626
}
17-
styleNearestElement(fiberNode?.child)
27+
styleNearestElement(fiberNode.child)
1828
}, [])
1929

2030
useEffect(() => {
2131
if (navigation.state !== "idle") return
32+
// biome-ignore lint/suspicious/noExplicitAny: accessing React internals
33+
const devTools = (window as any).__REACT_DEVTOOLS_GLOBAL_HOOK__
2234

23-
onCommitFiberRoot((root) =>
24-
traverseFiber(root.current, (fiberNode) => {
25-
if (fiberNode?.elementType?.name === "default" || fiberNode?.elementType?.name === "RenderedRoute") {
26-
styleNearestElement(fiberNode)
27-
}
28-
})
29-
)
30-
}, [navigation.state, styleNearestElement])
35+
for (const [rendererID] of devTools.renderers) {
36+
const fiberRoots = devTools.getFiberRoots(rendererID)
37+
for (const rootFiber of fiberRoots) {
38+
// biome-ignore lint/suspicious/noExplicitAny: we don't know the type
39+
traverseComponentTree(rootFiber.current, (fiberNode: any) => {
40+
if (fiberNode?.elementType?.name === "default" || fiberNode?.elementType?.name === "RenderedRoute") {
41+
styleNearestElement(fiberNode)
42+
}
43+
})
44+
}
45+
}
46+
}, [navigation.state, styleNearestElement, traverseComponentTree])
3147
}

0 commit comments

Comments
 (0)