Skip to content

Commit 5d19e1c

Browse files
authored
Fix: profiling crashes #30661 #28838 (#31024)
<!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please provide enough information so that others can review your pull request. The three fields below are mandatory. Before submitting a pull request, please make sure the following is done: 1. Fork [the repository](https://github.com/facebook/react) and create your branch from `main`. 2. Run `yarn` in the repository root. 3. If you've fixed a bug or added code that should be tested, add tests! 4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch TestName` is helpful in development. 5. Run `yarn test --prod` to test in the production environment. It supports the same options as `yarn test`. 6. If you need a debugger, run `yarn test --debug --watch TestName`, open `chrome://inspect`, and press "Inspect". 7. Format your code with [prettier](https://github.com/prettier/prettier) (`yarn prettier`). 8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only check changed files. 9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`). 10. If you haven't already, complete the CLA. Learn more about contributing: https://reactjs.org/docs/how-to-contribute.html --> ## Summary Profiling fails sometimes because `onProfilingStatus` is called repeatedly on some occasions, e.g. multiple calls to `getProfilingStatus`. Subsequent calls should be a no-op if the profiling status hasn't changed. Reported via #30661 #28838. > [!TIP] > Hide whitespace changes on this PR <img width="328" alt="screenshot showing the UI controls for hiding whitespace changes on GitHub" src="https://github.com/user-attachments/assets/036385cf-2610-4e69-a717-17c05d7ef047"> ## How did you test this change? <!-- Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes the user interface. How exactly did you verify that your PR solves the issue you wanted to solve? If you leave this empty, your PR will very likely be closed. --> Tested as part of Fusebox implementation of reload-to-profile. #31021
1 parent d4688df commit 5d19e1c

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

packages/react-devtools-shared/src/devtools/ProfilerStore.js

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ export default class ProfilerStore extends EventEmitter<{
289289
};
290290

291291
onProfilingStatus: (isProfiling: boolean) => void = isProfiling => {
292+
if (this._isProfiling === isProfiling) {
293+
return;
294+
}
295+
292296
if (isProfiling) {
293297
this._dataBackends.splice(0);
294298
this._dataFrontend = null;
@@ -315,36 +319,34 @@ export default class ProfilerStore extends EventEmitter<{
315319
});
316320
}
317321

318-
if (this._isProfiling !== isProfiling) {
319-
this._isProfiling = isProfiling;
322+
this._isProfiling = isProfiling;
320323

321-
// Invalidate suspense cache if profiling data is being (re-)recorded.
322-
// Note that we clear again, in case any views read from the cache while profiling.
323-
// (That would have resolved a now-stale value without any profiling data.)
324-
this._cache.invalidate();
324+
// Invalidate suspense cache if profiling data is being (re-)recorded.
325+
// Note that we clear again, in case any views read from the cache while profiling.
326+
// (That would have resolved a now-stale value without any profiling data.)
327+
this._cache.invalidate();
325328

326-
this.emit('isProfiling');
329+
this.emit('isProfiling');
327330

328-
// If we've just finished a profiling session, we need to fetch data stored in each renderer interface
329-
// and re-assemble it on the front-end into a format (ProfilingDataFrontend) that can power the Profiler UI.
330-
// During this time, DevTools UI should probably not be interactive.
331-
if (!isProfiling) {
332-
this._dataBackends.splice(0);
333-
this._rendererQueue.clear();
331+
// If we've just finished a profiling session, we need to fetch data stored in each renderer interface
332+
// and re-assemble it on the front-end into a format (ProfilingDataFrontend) that can power the Profiler UI.
333+
// During this time, DevTools UI should probably not be interactive.
334+
if (!isProfiling) {
335+
this._dataBackends.splice(0);
336+
this._rendererQueue.clear();
334337

335-
// Only request data from renderers that actually logged it.
336-
// This avoids unnecessary bridge requests and also avoids edge case mixed renderer bugs.
337-
// (e.g. when v15 and v16 are both present)
338-
this._rendererIDsThatReportedProfilingData.forEach(rendererID => {
339-
if (!this._rendererQueue.has(rendererID)) {
340-
this._rendererQueue.add(rendererID);
338+
// Only request data from renderers that actually logged it.
339+
// This avoids unnecessary bridge requests and also avoids edge case mixed renderer bugs.
340+
// (e.g. when v15 and v16 are both present)
341+
this._rendererIDsThatReportedProfilingData.forEach(rendererID => {
342+
if (!this._rendererQueue.has(rendererID)) {
343+
this._rendererQueue.add(rendererID);
341344

342-
this._bridge.send('getProfilingData', {rendererID});
343-
}
344-
});
345+
this._bridge.send('getProfilingData', {rendererID});
346+
}
347+
});
345348

346-
this.emit('isProcessingData');
347-
}
349+
this.emit('isProcessingData');
348350
}
349351
};
350352
}

0 commit comments

Comments
 (0)