Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ SECURE_NGROK_URL=https://secure-expensify-user.ngrok.io/
NGROK_URL=https://expensify-user.ngrok.io/
USE_NGROK=false
USE_WEB_PROXY=false
USE_WDYR=false
9 changes: 9 additions & 0 deletions PERFORMANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@

**Suggested:** [Deep Dive with the React DevTools creator](https://www.youtube.com/watch?v=nySib7ipZdk)

### Why Did You Render?
- Why Did You Render (WDYR) sends console notifications about potentially avoidable component re-renders.
- It can also help to simply track when and why a certain component re-renders.
- To enable it, set `USE_WDYR=true` in your `.env` file.
- You can add or exclude tracked components by their `displayName` in `wdyr.js`.
- Open the browser console to see WDYR notifications.

**Suggested** [Why Did You Render docs](https://github.com/welldone-software/why-did-you-render)

## Reconciliation

React is pretty smart and in many cases is able to tell if something needs to update. The process by which React goes about updating the "tree" or view heirarchy is called reconciliation. If React thinks something needs to update it will render it again. React also assumes that if a parent component rendered then it's child should also re-render.
Expand Down
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
"@testing-library/jest-native": "^3.4.2",
"@testing-library/react-native": "^7.0.2",
"@vercel/ncc": "^0.27.0",
"@welldone-software/why-did-you-render": "^6.2.0",
"ajv-cli": "^5.0.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^26.2.2",
Expand Down
1 change: 1 addition & 0 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '../wdyr';
import React from 'react';
import {LogBox} from 'react-native';
import {SafeAreaProvider} from 'react-native-safe-area-context';
Expand Down
30 changes: 30 additions & 0 deletions wdyr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Implements Why Did You Render (WDYR) in Dev

import React from 'react';
import Config from 'react-native-config';
import lodashGet from 'lodash/get';

const useWDYR = lodashGet(Config, 'USE_WDYR') === 'true';

if (useWDYR) {
const whyDidYouRender = require('@welldone-software/why-did-you-render');
whyDidYouRender(React, {
// Enable tracking in all pure components by default
trackAllPureComponents: true,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be false (the default)? PureComponent seems like the least likely to be re-rendering for bad reasons?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After doing more research and seeing this comment from one of the creators, it seems that tracking pure components by default is a better idea, as they might control big render trees.

So I will keep that as the default, but I also included a way to enable tracking in all components, as well as examples to enable tracking by component displayName.

Screen must be excluded when tracking all components to avoid the following error that crashes the app:

Uncaught Error: A navigator can only contain 'Screen', 'Group' or 'React.Fragment' as its direct children (found 'WDYRFunctionalComponent' for the screen 'Home'). To render this component in the navigator, pass it in the 'component' prop to 'Screen'.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok that works. Weird about the Screen component. Must have used this last before we added react navigation.


include: [
// Uncomment to enable tracking in all components. Must also uncomment /^Screen/ in exclude.
// /.*/,

// Uncomment to enable tracking by displayName, e.g.:
// /^Avatar/,
// /^ReportActionItem/,
// /^ReportActionItemSingle/,
],

exclude: [
// Uncomment to enable tracking in all components
// /^Screen/
],
});
}