-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Handle & render the _source property #406
Conversation
To take advantage of this, use the [transform-react-jsx-source](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-jsx-source) babel plugin. The `_source` property was added to react [last year](facebook/react@009b7c8) and can be used by development tools to track the source file & line of react elements. React Native is also [taking advantage of it](facebook/react-native#6351). Test Plan: - install the [transform-react-jsx-source](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-jsx-source) babel plugin - open the react devtools to an element that was created in your app (can't have been created by a library you're using, because those are probably pre-transpiled & ignored by babel)
frontend/PropState.js
Outdated
| * - if it has `/src/` in it, assume that's the project root | ||
| * - if it starts w/ `/Users/name/`, replace that with `~/` | ||
| */ | ||
| var shortFilePath = text => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this? I'd rather fix any environments that pass an absolute path. I've been meaning to check whether babelify and babel-loader do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like having an absolute path -- and it's critical for React Native's "open the file in your editor" functionality
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course, we could change it to include both an absolute path and a project-relative path? or sth. or the # that is how long the project prefix is, so we could do source.filePath.slice(source.prefixLength) or sth
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the project-relative path is always what you want. The packager would know where the root is.
|
lgtm |
|
|
||
| ### Supporting tools | ||
|
|
||
| - The babel plugin [trasnform-react-jsx-source](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-jsx-source) is required if you want react devtools to tell you the source file & line number of created react elements. It's display in the bottom of the right panel if the information is present. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's display → It's displayed
To take advantage of this, use the transform-react-jsx-source babel plugin.
The
_sourceproperty was added to react last year and can be used by development tools to track the source file & line of react elements. React Native is also taking advantage of it.Test Plan:
have been created by a library you're using, because those are probably
pre-transpiled & ignored by babel)
^
src/run.js:12