Skip to content

Commit 6f11185

Browse files
authored
Merge pull request #245 from HuolalaTech/optimize/network-lifecycle-in-replay
show whole lifecycle for network request when replay
2 parents 1e9dd04 + 9253db1 commit 6f11185

File tree

2 files changed

+28
-29
lines changed

2 files changed

+28
-29
lines changed

src/components/NetworkTable/index.less

+21-19
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,6 @@
3232
&.active {
3333
background-color: @tbody-select-bg;
3434
}
35-
&:nth-child(1) {
36-
width: 20%;
37-
}
38-
&:nth-child(2) {
39-
width: 38%;
40-
}
41-
&:nth-child(3) {
42-
width: 12%;
43-
}
44-
&:nth-child(4) {
45-
width: 10%;
46-
}
47-
&:nth-child(5) {
48-
width: 10%;
49-
}
50-
&:nth-child(6) {
51-
width: 10%;
52-
}
5335
&:last-child {
5436
border-right: none;
5537
}
@@ -77,6 +59,26 @@
7759
}
7860

7961
.network-list {
62+
td {
63+
&:nth-child(1) {
64+
width: 20%;
65+
}
66+
&:nth-child(2) {
67+
width: 38%;
68+
}
69+
&:nth-child(3) {
70+
width: 12%;
71+
}
72+
&:nth-child(4) {
73+
width: 10%;
74+
}
75+
&:nth-child(5) {
76+
width: 10%;
77+
}
78+
&:nth-child(6) {
79+
width: 10%;
80+
}
81+
}
8082
&__header {
8183
position: sticky;
8284
top: 0;
@@ -225,7 +227,7 @@
225227
width: 8%;
226228
}
227229
&:nth-child(4) {
228-
width: 15%;
230+
width: 100px;
229231
}
230232
}
231233
}

src/store/replay.ts

+7-10
Original file line numberDiff line numberDiff line change
@@ -252,39 +252,36 @@ export const useReplayStore = create<ReplayStore>((set, get) => ({
252252
const { allNetworkMsg, networkMsg } = get();
253253

254254
let networkIndex = 0;
255-
const eventSourceData: Record<string, SpyNetwork.RequestInfo> = {};
256-
const showedNetworkMsg: SpyNetwork.RequestInfo[] = [];
255+
const showedNetworkMsg: Map<string, SpyNetwork.RequestInfo> = new Map();
257256
while (
258257
networkIndex < allNetworkMsg.length &&
259258
allNetworkMsg[networkIndex].timestamp <= currentTime
260259
) {
261260
const { data } = allNetworkMsg[networkIndex];
262261
const { id, requestType, endTime, response } = data;
263-
// @ts-ignore
262+
264263
if (requestType === 'eventsource') {
265-
if (!eventSourceData[id]) {
264+
if (!showedNetworkMsg.has(id)) {
266265
const result = {
267266
...data,
268267
response: [{ time: endTime, data: response }],
269268
};
270-
eventSourceData[id] = result;
271-
showedNetworkMsg.push(result);
269+
showedNetworkMsg.set(id, result);
272270
} else {
273-
// 通过 response 数组引用直接修改
274-
eventSourceData[id].response.push({
271+
showedNetworkMsg.get(id)!.response.push({
275272
time: endTime,
276273
data: response,
277274
});
278275
}
279276
} else {
280-
showedNetworkMsg.push(data);
277+
showedNetworkMsg.set(id, data);
281278
}
282279
networkIndex += 1;
283280
}
284281

285282
set(
286283
produce((state) => {
287-
state.networkMsg = showedNetworkMsg;
284+
state.networkMsg = [...showedNetworkMsg.values()];
288285
}),
289286
);
290287
},

0 commit comments

Comments
 (0)