-
Notifications
You must be signed in to change notification settings - Fork 48.8k
update react perf docs (#8060) and (#6174) #8236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
docs/docs/addons-perf.md
Outdated
|
||
//If Perf is not accessible from console i.e throws RefrenceError: | ||
//Perf is not defined, create a global | ||
window.Perf = Perf; |
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 don't think this is something we want to tell everyone to do, is it?
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.
In this tutorial I am using only one file but in real projects developers use bable and webpack or other such tools. If we import Perf ES6 style in any file of our project we have to make it global to access it from console and @gaearon has mentioned it in issue #6174 . So I think we should let developers know solution to a common problem beforehand. What do you think ?
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 has been mentioned in the solution of issue #6174 . So I think it should be included so developers know how to solve it when they run into reference error.
docs/docs/addons-perf.md
Outdated
@@ -14,6 +14,10 @@ next: test-utils.html | |||
import Perf from 'react-addons-perf' // ES6 | |||
var Perf = require('react-addons-perf') // ES5 with npm | |||
var Perf = React.addons.Perf; // ES5 with react-with-addons.js | |||
|
|||
//If Perf is not accessible from console i.e throws RefrenceError: |
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.
nitpicks: spaces after //, Refrence misspelled
docs/docs/addons-perf.md
Outdated
@@ -32,7 +36,7 @@ See these articles by the [Benchling Engineering Team](http://benchling.engineer | |||
|
|||
If you're benchmarking or seeing performance problems in your React apps, make sure you're testing with the [minified production build](/react/downloads.html). The development build includes extra warnings that are helpful when building your apps, but it is slower due to the extra bookkeeping it does. | |||
|
|||
However, the perf tools described on this page only work when using the development build of React. Therefore, the profiler only serves to indicate the _relatively_ expensive parts of your app. | |||
However, the perf tools described on this page only work when using the development build of React. If you set NODE_ENV to _production_ than it will not work. Therefore, the profiler only serves to indicate the _relatively_ expensive parts of your app. |
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.
NODE_ENV is only applicable when compiling yourself - you might be using a CDN version. So I think this sentence is better just left out, the right way to refer to this is "using the development build" rather than "setting NODE_ENV".
docs/docs/addons-perf.md
Outdated
@@ -56,6 +60,33 @@ The following methods use the measurements returned by [`Perf.getLastMeasurement | |||
|
|||
* * * | |||
|
|||
## Example Usage: |
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.
no : needed
docs/docs/addons-perf.md
Outdated
@@ -56,6 +60,33 @@ The following methods use the measurements returned by [`Perf.getLastMeasurement | |||
|
|||
* * * | |||
|
|||
## Example Usage: | |||
|
|||
We will take the comments example from old official tutorial. The example code is availabe on [github](https://github.com/dhyey35/react-example-for-performance/blob/master/public/scripts/example.js). |
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.
Rather than referring to "the old official tutorial" how about just having a little bit of example code and then linking to somewhere that it's available as a html file where people can just drop into dev tools. It could be in the assets directory in the react website, I think that would make sense because we put some other html stuff there too.
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.
Where should I put my code in order to get it into assets dir on react website as I dont have access to it ? Examples directory of repo ?
docs/docs/addons-perf.md
Outdated
//Using react-with-addons.js in ES5 | ||
var Perf = React.addons.Perf; | ||
|
||
var Comment = React.createClass({ |
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.
our example code we're using ES6 for now - could you make this the same style as the other docs?
docs/docs/addons-perf.md
Outdated
rawMarkup: function() { | ||
var md = new Remarkable(); | ||
var rawMarkup = md.render(this.props.children.toString()); | ||
return { __html: rawMarkup }; |
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.
Could you avoid using this dangerous html stuff in example code?
docs/docs/addons-perf.md
Outdated
|
||
 | ||
|
||
A **Live Example** of the above code is available on [react-example-for-performance](https://react-example-for-performance.herokuapp.com/) |
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 best to avoid dependencies on new backends, especially a one-off herokuapp instance. Perhaps this could just be a static file on the react website itself.
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.
Where should I put the code to get it into assets dir of react website ?
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.
Comment about inconsistent code spacing.
docs/docs/addons-perf.md
Outdated
|
||
const Comment = (props) => { | ||
return ( | ||
<div className="comment"> |
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.
Minor: Looks like you have some inconsistent spacing here. (sometimes 2, sometimes 3)...
@davidwparker Fixed the inconsistent spacing issue. @lacker can you please tell me where should i put my example code as to get it into assets directory of react website which you mentioned in above comment
|
@lacker Can you please follow up on this? |
Hey, sorry I had a bit of email bankruptcy over the holiday break. Assets are in their own directories under |
docs/docs/addons-perf.md
Outdated
<span>{props.children.toString()}</span> | ||
</div> | ||
) | ||
} |
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.
@dhyey35 How about dropping return
?
const Comment = props => (
<div className="comment">
<h2 className="commentAuthor">
{props.author}
</h2>
<span>{props.children.toString()}</span>
</div>
);
docs/docs/addons-perf.md
Outdated
document.getElementById('content') | ||
); | ||
``` | ||
Open the developer console in the browser and type `Perf.start()` than followed by the action you want to monitor eg: submitting a form. Than type `Perf.stop()` in the console and than type `Perf.getLastMeasurements()` to get the measurements .See the Reference below for more methods. |
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.
"than" vs. "then"
docs/docs/addons-perf.md
Outdated
document.getElementById('content') | ||
); | ||
``` | ||
Open the developer console in the browser and type `Perf.start()` than followed by the action you want to monitor eg: submitting a form. Than type `Perf.stop()` in the console and than type `Perf.getLastMeasurements()` to get the measurements .See the Reference below for more methods. |
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.
the measurements .See the
Spacing in text
docs/docs/addons-perf.md
Outdated
@@ -14,6 +14,10 @@ next: test-utils.html | |||
import Perf from 'react-addons-perf' // ES6 | |||
var Perf = require('react-addons-perf') // ES5 with npm | |||
var Perf = React.addons.Perf; // ES5 with react-with-addons.js | |||
|
|||
// If Perf is not accessible from console i.e throws ReferenceError: | |||
// Perf is not defined, create a global |
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.
Question for understanding: Should it be available globally by default? When will it be available and when not? What circumstances trigger the different states?
fd1b36f
to
479de22
Compare
@andys8 I have made the changes you suggested. Can you please let me know if they are okay or need any changes ? @lacker I pushed the code to docs/css/perf-tutorial.css , docs/tutorial/perf-tutorial.html , docs/_js/perf-tutorial.min.js as docs/js is in the .gitignore file. Have I placed them correctly ? |
@dhyey35 Great, i appreciate your changes. |
docs/docs/addons-perf.md
Outdated
@@ -57,6 +62,34 @@ The following methods use the measurements returned by [`Perf.getLastMeasurement | |||
|
|||
* * * | |||
|
|||
## Example Usage | |||
|
|||
We will take the [simple example]() of a form which can be used to submit comments and then listing all comments. The example code is availabe on [github](https://github.com/dhyey35/react-example-for-performance/blob/master/public/scripts/example.js). |
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.
Looks like one of the links is missing here?
Hmm, the location of these files seems kind of weird - you are putting them through the site's build system when really you don't want any of that, you just want a static file. |
@lacker I removed the missing link which wasn't needed and made a single html file in |
Awesome, looks good! Thank you for writing this up! |
@lacker @gaearon @andys8 @davidwparker @zpao Thanks for helping me throughout the way and giving opportunity to beginners to contribute to such a big project. This was my first PR to a big project. You guys are awesome. |
Thanks for making the world a slightly-better-documented place ;-) |
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 appreciate the effort but I think this needs to be reworked to better match the rest of the docs. I'm going to revert this specific PR but I'll be happy to review a follow-up that addresses these specific concerns.
We will take simple example of a form which can be used to submit comments and then listing all comments. The example code is [available on GitHub](https://github.com/dhyey35/react-example-for-performance/blob/master/public/scripts/example.js). | ||
|
||
```javascript | ||
import { Component } from 'react' |
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.
This import is unused.
import { Component } from 'react' | ||
import Perf from 'react-addons-perf' | ||
|
||
const Comment = (props) => ( |
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.
We don't use this style of declaring components anywhere in the docs. We used function
everywhere because it's easier to understand for people new to ES6.
<span>{props.children.toString()}</span> | ||
</div> | ||
) | ||
//code... |
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.
What does this comment represent? I don't think it makes the example more clear.
//code... | ||
|
||
ReactDOM.render( | ||
<CommentBox />, |
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.
This component is named CommentBox
but the component declared above is called Comment
. What is the reason for the discrepancy?
document.getElementById('content') | ||
); | ||
``` | ||
Open the developer console in the browser and type `Perf.start()`. Then perform the action you want to monitor, like submitting a form. Finally, type `Perf.stop()` and `Perf.getLastMeasurements()` to get the measurements. See the Reference below for more methods. |
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.
The user reading this will likely miss the initial window.Perf
assignment because it's in another code snippet, and will get that error about Perf
being undefined.
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.
Perf.getLastMeasurements()
is an extremely low level method and gives information that has very little value to the user unless they know how to interpret it. This is definitely not what we should be suggesting to the user as an introductory example.
{ | ||
author: "Kevin Lacker", | ||
id: 1, | ||
text: "I Love React" |
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 we could have better more appropriate text than praising ourselves. 😉
Apologies for reverting—I want to get this in, but I just don't think it works as is. Happy to review this if you address the requested changes. |
@gaearon No problems, will address the requested changes. Should I submit a new PR or restore my branch perf-docs and push to it ? |
A new PR would be fine. 👍 |
Number 11 on checklist of issue #8060 -
Added example, console screenshot and link to live demo where user can open console and call Perf methods.