diff --git a/src/__tests__/profilerStore-test.js b/src/__tests__/profilerStore-test.js index 08f64b344b..f6ffcfe783 100644 --- a/src/__tests__/profilerStore-test.js +++ b/src/__tests__/profilerStore-test.js @@ -54,4 +54,21 @@ describe('ProfilerStore', () => { expect(store.profilerStore.getDataForRoot(rootB)).not.toBeNull(); }); + + it('should not allow new/saved profiling data to be set while profiling is in progress', () => { + utils.act(() => store.profilerStore.startProfiling()); + const fauxProfilingData = { + dataForRoots: new Map(), + }; + spyOn(console, 'warn'); + store.profilerStore.profilingData = fauxProfilingData; + expect(store.profilerStore.profilingData).not.toBe(fauxProfilingData); + expect(console.warn).toHaveBeenCalledTimes(1); + expect(console.warn).toHaveBeenCalledWith( + 'Profiling data cannot be updated while profiling is in progress.' + ); + utils.act(() => store.profilerStore.stopProfiling()); + store.profilerStore.profilingData = fauxProfilingData; + expect(store.profilerStore.profilingData).toBe(fauxProfilingData); + }); }); diff --git a/src/devtools/ProfilerStore.js b/src/devtools/ProfilerStore.js index 30e1934600..f4901287ea 100644 --- a/src/devtools/ProfilerStore.js +++ b/src/devtools/ProfilerStore.js @@ -144,6 +144,13 @@ export default class ProfilerStore extends EventEmitter { return this._dataFrontend; } set profilingData(value: ProfilingDataFrontend | null): void { + if (this._isProfiling) { + console.warn( + 'Profiling data cannot be updated while profiling is in progress.' + ); + return; + } + this._dataBackends.splice(0); this._dataFrontend = value; this._initialRendererIDs.clear();