Skip to content

Commit 8eaf909

Browse files
committed
add react info
1 parent 33f71d1 commit 8eaf909

4 files changed

Lines changed: 46 additions & 7 deletions

File tree

packages/devtool-extenstion/extension/core/background.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ const saveCatchData = (request, { id: tabId, title }, subType) => {
152152
},
153153
useReducer: {},
154154
context: {},
155+
reactInfo: {},
155156
};
156157
chunkData[tabId] = [];
157158
}
@@ -208,6 +209,10 @@ const saveCatchData = (request, { id: tabId, title }, subType) => {
208209
}
209210
});
210211
}
212+
213+
if (parsedData.reactInfo) {
214+
catchData[tabId].reactInfo = parsedData.reactInfo;
215+
}
211216
};
212217

213218
const setAppPopup = (isActive, tabId) => {

packages/devtool-extenstion/extension/core/hook.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ export function installHook(target, settings) {
77
context: {},
88
};
99

10+
let renderer = null;
11+
let isDebuggingStarted = false;
12+
13+
const reactInfo = {};
14+
1015
const dispatchAction = (event) => {
1116
if(event.type === "useReducer" && fiberNodeToDebug.useReducer[event.debugId]) {
1217
fiberNodeToDebug.useReducer[event.debugId].hook.queue.dispatch(event.data);
@@ -33,7 +38,9 @@ export function installHook(target, settings) {
3338
const sendDataToDevtool = () => {
3439
const helpers = window.__REACT_CONTEXT_DEVTOOL_GLOBAL_HOOK.helpers;
3540

36-
const dataToSend = {};
41+
const dataToSend = {
42+
reactInfo,
43+
};
3744

3845
dataToSend.context = Object.keys(fiberNodeToDebug.context).reduce((memo, key) => {
3946
const debugObj = fiberNodeToDebug.context[key];
@@ -77,9 +84,6 @@ export function installHook(target, settings) {
7784
}, "*");
7885
};
7986

80-
let renderer = null;
81-
let isDebuggingStarted = false;
82-
8387
/**
8488
* Debug for React useReducer API
8589
*
@@ -298,6 +302,9 @@ export function installHook(target, settings) {
298302

299303
renderer = params.renderer;
300304

305+
reactInfo.version = renderer ? renderer.version : "";
306+
reactInfo.rendererPackageName = renderer ? renderer.rendererPackageName : "";
307+
301308
const fiberRoot = reactDebtoolGlobalhook.getFiberRoots(params.id).keys().next().value;
302309

303310
if (fiberRoot) {
@@ -372,6 +379,7 @@ export function installHook(target, settings) {
372379
window.addEventListener('message', event => {
373380
if (event.data.source === "react-devtools-detector") {
374381
if (settings.startDebugWhen === "pageLoad") {
382+
reactInfo.mode = event.data.reactBuildType;
375383
startDebug();
376384
}
377385
}

packages/devtool-extenstion/src/containers/Header/index.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,26 @@ import AppContext from "Containers/AppContext";
55
import "./index.scss";
66

77
const Header = () => {
8-
const { appData: { tab } } = useContext(AppContext);
8+
const {
9+
appData: { tab, reactInfo },
10+
} = useContext(AppContext);
911

10-
return <header>{tab.title || "React Context Devtool"}</header>;
12+
return (
13+
<header>
14+
<div>{tab.title || "React Context Devtool"}</div>
15+
<div>
16+
{reactInfo.version ? (
17+
<span className="pill">
18+
{reactInfo.rendererPackageName
19+
? `${reactInfo.rendererPackageName}@`
20+
: null}
21+
{reactInfo.version}
22+
</span>
23+
) : null}
24+
{reactInfo.mode ? <span className="pill">{reactInfo.mode}</span> : null}
25+
</div>
26+
</header>
27+
);
1128
};
1229

1330
export default Header;
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
header {
2+
display: flex;
23
align-items: center;
4+
justify-content: space-between;
35
background-color: var(--header-bg-color);
46
border-bottom: 1px solid var(--border-color);
5-
display: flex;
67
font-size: 0.9rem;
78
padding: 0.7rem 1rem;
9+
10+
.pill {
11+
background-color: var(--primary-color);
12+
padding: 2px 5px;
13+
margin-left: 10px;
14+
border-radius: 3px;
15+
font-size: 0.8rem;
16+
}
817
}

0 commit comments

Comments
 (0)