mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 12:20:20 +01:00
* took codes.json from the 15-dev branch * fixed react:extract-errors task in gulpfile * generated error codes * Revert "generated error codes" This reverts commit b8f3aeed9d8f0d469edd5f6623fa6090930594d8. * Added a README for the error code system |
||
|---|---|---|
| .. | ||
| __tests__ | ||
| codes.json | ||
| dev-expression-with-codes.js | ||
| evalToString.js | ||
| gulp-extract-errors.js | ||
| invertObject.js | ||
| README.md | ||
| Types.js | ||
The error code system substitutes React's invariant error messages with error IDs to provide a better debugging support in production. Check out the blog post here.
Note for cutting a new React release
- For each release, we run
gulp react:extract-errorsto update the error codes before callingnpm run build. The build process usescodes.jsonfor a production (minified) build; there should be no warning likeError message "foo" cannot be foundfor a successful release. - The updated
codes.jsonfile should be synced back to the master branch. The error decoder page in our documentation site usescodes.jsonfrom master; if the json file has been updated, the docs site should also be rebuilt (rake copy_error_codesis included in the defaultrake releasetask). - It's not recommended to run
gulp react:extract-errorsdirectly in master since it may contain commits that are not cherry-picked to a release branch. These error messages might be changed/removed before cutting a new release, and we don't want to add intermediate/temporary error messages tocodes.json. However, if a PR changes an existing error message and there's a specific production test (which is rare), it's ok to updatecodes.jsonfor that. Please usegulp react:extract-errorsand don't edit the file manually.
Structure
The error code system consists of 5 parts:
codes.jsoncontains the mapping from IDs to error messages. This file is generated by the Gulp plugin and is used by both the Babel plugin and the error decoder page in our documentation. This file is append-only, which means an existing code in the file will never be changed/removed.gulp-extract-errors.jsis a gulp plugin that traverses our codebase and updatescodes.json. Use it by callinggulp react:extract-errors.dev-expression-with-codes.jsis a Babel pass that rewrites error messages to IDs for a production (minified) build. Notice that this plugin is not in.babelrc; it's being used in thegulpfile.jsand it has to be run beforerewrite-modulessince we search forrequire('invariant')but notrequire('./invariant').reactProdInvariant.jsis the replacement forinvariantin production. This file gets imported by the Babel plugin and should not be used manually.ErrorDecoderComponentis a React component that lives at https://facebook.github.io/react/docs/error-decoder.html. This page takes parameters like?invariant=109&args[]=Fooand displays a corresponding error message. Our documentation site'sRakefilehas a task (bundle exec rake copy_error_codes) for adding the latestcodes.jsonto the error decoder page. This task is included in the defaultbundle exec rake releasetask.