mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Fix potential RTE caused by setting (saved) profiling data while profiling is in progress
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user