react / react/react

Improve "native" component stacks host component frames

Open
#22,531 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Component: Developer Tools Size: Small-Medium Type: Discussion
Dominant language
JavaScript
Stars
251k
Forks
51.4k
Avg merge
2d 4h
Merged PRs (30d)
53

Description

React and React DevTools generate component stacks in the same format as native Error stacks. For user components (class and function components) this is done by intentionally causing the component's render method to throw an Error, and then stitching the error stack frames together:
https://github.com/facebook/react/blob/5fa4d79b00988f354073bc27313363dd5cce9cd3/packages/react-devtools-shared/src/backend/DevToolsComponentStackFrame.js#L62-L203

This results in a component stack like this:
image

But for "host components" (e.g. HTMLDivElement or View) when we have no source location to show, we fall back to showing just "at div" or "at View".

We could probably more closely mirror what JavaScript engines do by appending a "location" like (native) or (unknown location) (as the v8 docs suggest) or (anonymous) as v8 seems to actually do in testing.

The trick would be matching the specific browser/engine's behavior for this. For example, running the following code in Chrome or Node...

JSON.stringify({}, () => console.log(new Error('')));

...will show the stack frame:

    at JSON.stringify (<anonymous>)

while Firefox will show:

Error: 
    <anonymous> file:///path/to/script:7

Improving this format so that host components more closely mirror native Error stacks will help simplify things like React Native's error parsing.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in packages/react-devtools-shared/src/backend/DevToolsComponentStackFrame.js, especially lines 62-203, and compare its host-component fallback with the V8 and Firefox examples in the issue. Check how the resulting stack is consumed by React Native error parsing. Done means host frames use an engine-appropriate location format without changing user-component stack behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.