Skip to content

Commit f27273c

Browse files
committed
fix: wait for all renderer profiling data before resolving
1 parent 3ba4061 commit f27273c

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

packages/agent-react-devtools/src/devtools-bridge.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ interface PendingInspection {
2727
interface PendingProfilingCollect {
2828
resolve: () => void;
2929
timer: ReturnType<typeof setTimeout>;
30+
remaining: number;
3031
}
3132

3233
export class DevToolsBridge {
@@ -154,13 +155,14 @@ export class DevToolsBridge {
154155
});
155156
}
156157

158+
const expected = this.rendererIds.size;
157159
return new Promise<void>((resolve) => {
158160
const timer = setTimeout(() => {
159161
this.pendingProfilingCollect = null;
160162
resolve();
161163
}, 5000);
162164

163-
this.pendingProfilingCollect = { resolve, timer };
165+
this.pendingProfilingCollect = { resolve, timer, remaining: expected };
164166
});
165167
}
166168

@@ -316,12 +318,15 @@ export class DevToolsBridge {
316318
// We forward it to the profiler for processing.
317319
this.profiler.processProfilingData(payload);
318320

319-
// Resolve the pending collect promise now that data has arrived
321+
// Resolve once all expected renderer responses have arrived
320322
if (this.pendingProfilingCollect) {
321-
clearTimeout(this.pendingProfilingCollect.timer);
322-
const pending = this.pendingProfilingCollect;
323-
this.pendingProfilingCollect = null;
324-
pending.resolve();
323+
this.pendingProfilingCollect.remaining--;
324+
if (this.pendingProfilingCollect.remaining <= 0) {
325+
clearTimeout(this.pendingProfilingCollect.timer);
326+
const pending = this.pendingProfilingCollect;
327+
this.pendingProfilingCollect = null;
328+
pending.resolve();
329+
}
325330
}
326331
}
327332

0 commit comments

Comments
 (0)