Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Conversation

@jaredly
Copy link
Contributor

@jaredly jaredly commented Aug 5, 2016

To take advantage of this, use the transform-react-jsx-source babel plugin.

The _source property 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:

  • install the 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)

image
^ src/run.js:12

jaredly added 2 commits August 5, 2016 09:53
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)
@jaredly
Copy link
Contributor Author

jaredly commented Aug 17, 2016

ping @spicyj or @frantic?

@ghost ghost added the CLA Signed label Aug 17, 2016
* - if it has `/src/` in it, assume that's the project root
* - if it starts w/ `/Users/name/`, replace that with `~/`
*/
var shortFilePath = text => {
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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

Copy link
Contributor

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.

@sophiebits
Copy link
Contributor

lgtm

@ghost ghost added the CLA Signed label Aug 17, 2016
@jaredly jaredly merged commit f2fe9fd into facebook:master Aug 17, 2016
@jaredly jaredly deleted the jsx-source branch August 17, 2016 22:07

### 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.

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants