-
Notifications
You must be signed in to change notification settings - Fork 50.9k
__source makes component stack less useful #12058
Description
Do you want to request a feature or report a bug?
Somewhere in between.
What is the current behavior?
When I enable babel-plugin-transform-react-jsx-source to automatically add a __source prop to every component in development, the component stack displayed for certain React warnings changes from displaying the (inferred) name of the rendering component to displaying the filename and line number of the occurrence.
React also has access to the file path, but it is stripped and only the filename is included. This seems to be based on the assumption that the name of a file always maps exactly to the name of the component it exports. In practice, many people place components in ComponentName/index.js, so __source currently makes the stack less useful.
For example, compare:
in DownloadDropdown (created by Foo)
in Foo (created by Bar)
in div (created by Bar)
in div (created by Bar)
in div (created by Section)
in section (created by Section)
in Section (created by Bar)
in div (created by App)
in main (created by App)
...
to:
in DownloadDropdown (at index.js:53)
in Foo (at index.js:183)
in div (at index.js:182)
in div (at index.js:175)
in div (at index.js:29)
in section (at index.js:28)
in Section (at index.js:173)
in div (at index.js:26)
in main (at index.js:24)
...
What is the expected behavior?
I would like the stack to include the full file path, or at least to include the inferred component name alongside the filename.
Would you accept a PR for either option?
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
React 16.2.0. This was introduced in #6771 for 15.2.0.