Skip to content

DevTools: guard against undefined component stack in Profiler SidebarEventInfo#185

Closed
everettbu wants to merge 1 commit into
mainfrom
fix/profiler-crash-35049
Closed

DevTools: guard against undefined component stack in Profiler SidebarEventInfo#185
everettbu wants to merge 1 commit into
mainfrom
fix/profiler-crash-35049

Conversation

@everettbu

@everettbu everettbu commented Dec 12, 2025

Copy link
Copy Markdown

Mirror of facebook/react#35054
Original author: Abhra0404


Fixes a crash in the DevTools Profiler where calling .map on an undefined component stack could throw: "Cannot read properties of undefined (reading 'map')". See issue react/react#35049.

What I changed:

  • Ensure stackToComponentLocations(componentStack) is treated as an array before calling .map in packages/react-devtools-shared/src/devtools/views/Profiler/SidebarEventInfo.js.
  • Removed inline Flow type annotations in SidebarEventInfo.js to keep the file valid JavaScript in this build.

Why:

  • When componentStack was undefined (e.g. during navigation in React Native), the code attempted to call .map on the result, causing the Profiler to crash. Guarding the .map call prevents the crash.

Notes / Testing:

  • The fix was committed to branch fix/profiler-crash-35049 in my fork (Abhra0404/react).
  • Please review the removal of Flow annotations; if you prefer Flow types retained, I can reintroduce them in a Flow-compatible way.

This PR references and aims to address react/react#35049.

…o.js; remove type annotations for JS compatibility. Fixes react/react#35049
@greptile-apps

greptile-apps Bot commented Dec 12, 2025

Copy link
Copy Markdown

Greptile Overview

Greptile Summary

This PR fixes a crash in the DevTools Profiler that occurred when componentStack was undefined during navigation in React Native. The fix adds a defensive guard (|| []) to ensure .map is always called on an array, preventing the "Cannot read properties of undefined (reading 'map')" error.

Key changes:

  • Added null-safety guard: (stackToComponentLocations(componentStack) || []) on line 81
  • Removed Flow type annotations (FunctionLocationProps, SchedulingEventProps) to maintain JavaScript compatibility
  • Removed return type annotation from SidebarEventInfo function

Note: The defensive || [] guard is technically redundant based on the stackToComponentLocations implementation (which always returns an array), but provides additional safety against unexpected edge cases or future changes.

Confidence Score: 4/5

  • This PR is safe to merge with minimal risk - addresses a specific crash with defensive programming
  • The fix is defensive and won't introduce new issues. The || [] guard ensures robustness even though stackToComponentLocations theoretically always returns an array. Removing Flow annotations is acceptable for JS files. Score of 4 (not 5) because the root cause analysis isn't fully clear - the defensive fix works around a symptom that theoretically shouldn't occur based on the stackToComponentLocations implementation.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
packages/react-devtools-shared/src/devtools/views/Profiler/SidebarEventInfo.js 4/5 Adds defensive null-safety guard for stackToComponentLocations call and removes Flow type annotations for JS compatibility

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@everettbu everettbu added the Resolution: Stale Automatically closed due to inactivity label Feb 9, 2026
@github-actions

Copy link
Copy Markdown

Closing this pull request after a prolonged period of inactivity. If this issue is still present in the latest release, please ask for this pull request to be reopened. Thank you!

@github-actions github-actions Bot closed this Feb 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Resolution: Stale Automatically closed due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants