-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
[NO QA] Add docs describing react strict mode in detail #48165
Merged
mountiny
merged 4 commits into
Expensify:main
from
software-mansion-labs:kicu/update-strictmode-docs
Sep 2, 2024
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Usage of react concurrent mode and StrictMode | ||
## Concurrent react | ||
This App is rendered using react concurrent mode, which is the direction that React seems to be moving. | ||
|
||
Concurrent mode enables a lot of new behaviours in react, most importantly renders can be interrupted by React, re-run or run more than once. This is supposed to make react more performant and webapps more responsive to user actions. | ||
|
||
Further reading: | ||
- [What is Concurrent React](https://react.dev/blog/2022/03/29/react-v18#what-is-concurrent-react) | ||
|
||
## StrictMode | ||
Because the previously described react mode could potentially introduce new bugs in the code (related to parallel rendering) we are also using `<StrictMode />`. | ||
This is a recommendation from React team as per react official docs. | ||
|
||
`<StrictMode>` is a component that wraps the whole App in (or parts of App) and it runs extra checks and extra behaviors only in dev. So in essence this is a developer tool. | ||
|
||
### Temporarily disabling StrictMode for dev | ||
Strict mode *by default always* wraps entire Expensify App component tree. This happens in `src/App.tsx`. | ||
|
||
However, it might happen you want to temporarily disable `StrictMode` when developing, to verify that your code behaves properly. | ||
|
||
To do that: | ||
- go to `src/CONFIG.ts` | ||
- set `USE_REACT_STRICT_MODE_IN_DEV` flag to `false` | ||
|
||
_Important note_: this ☝️flag is strictly for developers. It does not affect production builds of React. | ||
StrictMode is supposed to always wrap your App regardless of environment, and it will simply do nothing when run on production react build. | ||
Only use this flag for local development and testing, but do not make it depending on `NODE_ENV` or any other env vars. | ||
|
||
sources: | ||
- [StrictMode docs](https://react.dev/reference/react/StrictMode) | ||
- [StrictMode recommended usage](https://react.dev/reference/react/StrictMode) | ||
- [Original PR introducing this feature](https://github.com/Expensify/App/pull/42592) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
(to me as a first time person reading this, reading react mode was slightly confusing, concurrent seemed more obvious. This is very subjective, I just mean it as suggestion :) )
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.
good suggestion, updated 👍 suggestions from first time readers are especially useful, since I have already worked on this and might be biased ;)