[DevTools] fix: don't show empty suspended by section#689
Conversation
Greptile SummaryThis PR adds a three-line guard to
Confidence Score: 2/5
Important Files Changed
Last reviewed commit: 4e4d138 |
| if (groups.length === 0) { | ||
| return null; | ||
| } |
There was a problem hiding this comment.
Early return suppresses unknownSuspenders messages
groups is only non-empty when suspendedBy contains items. However, the early-exit guard at lines 466–468 lets execution continue when suspendedBy is null/empty and inspectedElement.unknownSuspenders is not UNKNOWN_SUSPENDERS_NONE (i.e., it is UNKNOWN_SUSPENDERS_REASON_PRODUCTION, UNKNOWN_SUSPENDERS_REASON_OLD_VERSION, or UNKNOWN_SUSPENDERS_REASON_THROWN_PROMISE). In those cases groups will always be empty, so this new return null will silently discard the informative unknownSuspenders message that was computed in the switch statement just above.
Concretely: a production-mode component that is suspended with no tracked suspenders would previously show:
"Something suspended but we don't know the exact reason in production builds of React…"
With this change it now renders nothing at all.
The guard should also require that unknownSuspenders is null before short-circuiting:
| if (groups.length === 0) { | |
| return null; | |
| } | |
| if (groups.length === 0 && unknownSuspenders === null) { | |
| return null; | |
| } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/react-devtools-shared/src/devtools/views/Components/InspectedElementSuspendedBy.js
Line: 587-589
Comment:
**Early return suppresses `unknownSuspenders` messages**
`groups` is only non-empty when `suspendedBy` contains items. However, the early-exit guard at lines 466–468 lets execution continue when `suspendedBy` is null/empty _and_ `inspectedElement.unknownSuspenders` is **not** `UNKNOWN_SUSPENDERS_NONE` (i.e., it is `UNKNOWN_SUSPENDERS_REASON_PRODUCTION`, `UNKNOWN_SUSPENDERS_REASON_OLD_VERSION`, or `UNKNOWN_SUSPENDERS_REASON_THROWN_PROMISE`). In those cases `groups` will always be empty, so this new `return null` will silently discard the informative `unknownSuspenders` message that was computed in the `switch` statement just above.
Concretely: a production-mode component that is suspended with no tracked suspenders would previously show:
> "Something suspended but we don't know the exact reason in production builds of React…"
With this change it now renders nothing at all.
The guard should also require that `unknownSuspenders` is null before short-circuiting:
```suggestion
if (groups.length === 0 && unknownSuspenders === null) {
return null;
}
```
How can I resolve this? If you propose a fix, please make it concise.|
Upstream PR was closed or merged. Code is synced via branch mirror. |
Mirror of facebook/react#36011
Original author: hoxyq
The potential paddings and margins for the empty block are already handled via CSS selectors.