Fix potential RTE caused by setting (saved) profiling data while profiling is in progress
Brian Vaughn committed
May 23, 2019 at 14:49 UTC
408fbee23b24c247df4b3bae2abf1fe0283fc0ab
2 files changed
+24
src/__tests__/profilerStore-test.js
+17
@@ -54,4 +54,21 @@ describe('ProfilerStore', () => {
54
55
expect(store.profilerStore.getDataForRoot(rootB)).not.toBeNull();
56
});
57
+
58
+ it('should not allow new/saved profiling data to be set while profiling is in progress', () => {
59
+ utils.act(() => store.profilerStore.startProfiling());
60
+ const fauxProfilingData = {
61
+ dataForRoots: new Map(),
62
+ };
63
+ spyOn(console, 'warn');
64
+ store.profilerStore.profilingData = fauxProfilingData;
65
+ expect(store.profilerStore.profilingData).not.toBe(fauxProfilingData);
66
+ expect(console.warn).toHaveBeenCalledTimes(1);
67
+ expect(console.warn).toHaveBeenCalledWith(
68
+ 'Profiling data cannot be updated while profiling is in progress.'
69
+ );
70
+ utils.act(() => store.profilerStore.stopProfiling());
71
+ store.profilerStore.profilingData = fauxProfilingData;
72
+ expect(store.profilerStore.profilingData).toBe(fauxProfilingData);
73
+ });
74
});
src/devtools/ProfilerStore.js
+7
@@ -144,6 +144,13 @@ export default class ProfilerStore extends EventEmitter {
144
return this._dataFrontend;
145
}
146
set profilingData(value: ProfilingDataFrontend | null): void {
147
+ if (this._isProfiling) {
148
+ console.warn(
149
+ 'Profiling data cannot be updated while profiling is in progress.'
150
+ );
151
+ return;
152
+ }
153
+
154
this._dataBackends.splice(0);
155
this._dataFrontend = value;
156
this._initialRendererIDs.clear();