Skip to content
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

[Outdated; needs revision] Add support for normal errors to error code infra #15072

Closed
wants to merge 5 commits into from

Conversation

acdlite
Copy link
Collaborator

@acdlite acdlite commented Mar 9, 2019

Based on #15071

Refer to the base PR for more context


This compiles normal error constructors (new Error(...) and Error(...)) to ReactError in and ReactErrorProd, adding support to our error code replacement infra.

It also adds a lint rule to enforce that error messages are written in an extraction-friendly format.

Error messages must be a concatenation of strings and string literals. This is partly an artificial restriction, because I could generate a template string even from a dynamic expression, but requiring the use of a template literal for dynamic values helps prevent mistakes like const msg = 'string'; throw new Error(msg).

You can add extract-error/skip to messages that don't need to be replaced with an error code.

@acdlite acdlite changed the title Minify normal errors too Add support for normal errors to error code infra Mar 9, 2019
@sizebot
Copy link

sizebot commented Mar 9, 2019

React: size: 🔺+0.3%, gzip: 🔺+0.5%

ReactDOM: size: -0.1%, gzip: -0.3%

Details of bundled changes.

Comparing: aece811...8fad8da

react

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react.development.js -0.4% -0.5% 106.85 KB 106.46 KB 27.05 KB 26.93 KB UMD_DEV
react.production.min.js 🔺+0.3% 🔺+0.5% 12.01 KB 12.04 KB 4.64 KB 4.67 KB UMD_PROD
react.profiling.min.js +0.2% -0.0% 14.17 KB 14.2 KB 5.18 KB 5.18 KB UMD_PROFILING
react.development.js -0.6% -0.7% 69.61 KB 69.22 KB 17.98 KB 17.85 KB NODE_DEV
react.production.min.js 🔺+0.5% 🔺+0.6% 6.44 KB 6.47 KB 2.67 KB 2.69 KB NODE_PROD
React-dev.js -0.8% -0.7% 68 KB 67.46 KB 17.33 KB 17.2 KB FB_WWW_DEV
React-prod.js 🔺+0.3% 🔺+0.4% 16.07 KB 16.11 KB 4.25 KB 4.27 KB FB_WWW_PROD
React-profiling.js +0.3% +0.4% 16.07 KB 16.11 KB 4.25 KB 4.27 KB FB_WWW_PROFILING

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js -0.1% -0.1% 894.19 KB 893.68 KB 201.97 KB 201.86 KB UMD_DEV
react-dom.production.min.js -0.1% -0.3% 105.6 KB 105.46 KB 34.2 KB 34.11 KB UMD_PROD
react-dom.profiling.min.js -0.1% -0.2% 108.61 KB 108.46 KB 34.8 KB 34.72 KB UMD_PROFILING
react-dom.development.js -0.1% -0.1% 888.82 KB 888.3 KB 200.41 KB 200.3 KB NODE_DEV
react-dom.production.min.js -0.1% -0.2% 105.6 KB 105.46 KB 33.65 KB 33.57 KB NODE_PROD
react-dom.profiling.min.js -0.1% -0.3% 108.71 KB 108.57 KB 34.23 KB 34.13 KB NODE_PROFILING
ReactDOM-dev.js -0.1% -0.1% 914.91 KB 914.18 KB 202.21 KB 202.07 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+0.1% -0.0% 338.3 KB 338.68 KB 62.29 KB 62.28 KB FB_WWW_PROD
ReactDOM-profiling.js 0.0% -0.0% 344.97 KB 345.08 KB 63.69 KB 63.68 KB FB_WWW_PROFILING
react-dom-unstable-fire.development.js -0.1% -0.1% 894.52 KB 894 KB 202.1 KB 202 KB UMD_DEV
react-dom-unstable-fire.production.min.js -0.1% -0.3% 105.61 KB 105.47 KB 34.21 KB 34.12 KB UMD_PROD
react-dom-unstable-fire.profiling.min.js -0.1% -0.2% 108.62 KB 108.48 KB 34.81 KB 34.72 KB UMD_PROFILING
react-dom-unstable-fire.development.js -0.1% -0.1% 889.14 KB 888.63 KB 200.54 KB 200.43 KB NODE_DEV
react-dom-unstable-fire.production.min.js -0.1% -0.2% 105.61 KB 105.47 KB 33.66 KB 33.58 KB NODE_PROD
react-dom-unstable-fire.profiling.min.js -0.1% -0.3% 108.73 KB 108.58 KB 34.24 KB 34.14 KB NODE_PROFILING
ReactFire-dev.js -0.1% -0.1% 914.1 KB 913.36 KB 202.25 KB 202.1 KB FB_WWW_DEV
ReactFire-prod.js 🔺+0.1% -0.0% 326.96 KB 327.34 KB 59.99 KB 59.96 KB FB_WWW_PROD
ReactFire-profiling.js 0.0% -0.0% 333.57 KB 333.68 KB 61.36 KB 61.34 KB FB_WWW_PROFILING
react-dom-unstable-new-scheduler.development.js -0.1% -0.1% 887.32 KB 886.81 KB 199.83 KB 199.72 KB NODE_DEV
react-dom-unstable-new-scheduler.production.min.js 🔺+0.3% 🔺+0.2% 103.67 KB 103.95 KB 33.13 KB 33.2 KB NODE_PROD
react-dom-unstable-new-scheduler.profiling.min.js +0.3% +0.1% 107.02 KB 107.3 KB 34.02 KB 34.07 KB NODE_PROFILING
ReactDOMNewScheduler-dev.js -0.1% -0.1% 914.94 KB 914.21 KB 202.22 KB 202.08 KB FB_WWW_DEV
ReactDOMNewScheduler-prod.js 🔺+0.1% 🔺+0.2% 332.28 KB 332.68 KB 61.82 KB 61.92 KB FB_WWW_PROD
ReactDOMNewScheduler-profiling.js +0.1% +0.1% 337.72 KB 338.11 KB 62.82 KB 62.89 KB FB_WWW_PROFILING
react-dom-test-utils.development.js -0.6% -0.9% 52.68 KB 52.37 KB 14.33 KB 14.2 KB UMD_DEV
react-dom-test-utils.production.min.js 🔺+0.3% 🔺+0.3% 10.52 KB 10.56 KB 3.89 KB 3.91 KB UMD_PROD
react-dom-test-utils.development.js -0.6% -0.9% 52.41 KB 52.09 KB 14.26 KB 14.14 KB NODE_DEV
react-dom-test-utils.production.min.js 🔺+0.3% 🔺+0.5% 10.31 KB 10.34 KB 3.82 KB 3.84 KB NODE_PROD
ReactTestUtils-dev.js -0.9% -0.9% 50.66 KB 50.2 KB 13.62 KB 13.5 KB FB_WWW_DEV
react-dom-unstable-native-dependencies.development.js -0.7% -0.8% 60.76 KB 60.31 KB 15.85 KB 15.72 KB UMD_DEV
react-dom-unstable-native-dependencies.production.min.js 🔺+0.3% 🔺+0.6% 10.69 KB 10.72 KB 3.66 KB 3.68 KB UMD_PROD
react-dom-unstable-native-dependencies.development.js -0.8% -0.8% 60.43 KB 59.98 KB 15.72 KB 15.59 KB NODE_DEV
react-dom-unstable-native-dependencies.production.min.js 🔺+0.3% 🔺+0.5% 10.42 KB 10.46 KB 3.56 KB 3.58 KB NODE_PROD
ReactDOMUnstableNativeDependencies-dev.js -0.9% -0.9% 58.91 KB 58.36 KB 14.9 KB 14.77 KB FB_WWW_DEV
ReactDOMUnstableNativeDependencies-prod.js 🔺+0.2% 🔺+0.4% 26.14 KB 26.19 KB 5.25 KB 5.28 KB FB_WWW_PROD
react-dom-server.browser.development.js -0.3% -0.3% 136.52 KB 136.12 KB 35.91 KB 35.81 KB UMD_DEV
react-dom-server.browser.production.min.js 🔺+0.6% 🔺+0.7% 19.24 KB 19.35 KB 7.24 KB 7.29 KB UMD_PROD
react-dom-server.browser.development.js -0.3% -0.3% 132.65 KB 132.25 KB 34.98 KB 34.88 KB NODE_DEV
react-dom-server.browser.production.min.js 🔺+0.6% 🔺+0.8% 19.17 KB 19.28 KB 7.23 KB 7.28 KB NODE_PROD
ReactDOMServer-dev.js -0.4% -0.3% 135.04 KB 134.49 KB 34.69 KB 34.58 KB FB_WWW_DEV
ReactDOMServer-prod.js 🔺+0.5% 🔺+0.9% 47.7 KB 47.96 KB 10.95 KB 11.04 KB FB_WWW_PROD
react-dom-server.node.development.js -0.3% -0.3% 134.59 KB 134.19 KB 35.53 KB 35.42 KB NODE_DEV
react-dom-server.node.production.min.js 🔺+0.5% 🔺+0.9% 20.03 KB 20.14 KB 7.53 KB 7.59 KB NODE_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 3.66 KB 3.66 KB 1.45 KB 1.45 KB UMD_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.2% 1.05 KB 1.05 KB 635 B 636 B NODE_PROD
react-dom-unstable-fizz.node.development.js 0.0% +0.1% 3.74 KB 3.74 KB 1.43 KB 1.43 KB NODE_DEV
react-dom-unstable-fizz.node.production.min.js 0.0% 🔺+0.2% 1.1 KB 1.1 KB 665 B 666 B NODE_PROD

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-art.development.js -0.1% -0.1% 639.96 KB 639.41 KB 138.16 KB 138.06 KB UMD_DEV
react-art.production.min.js -0.1% -0.3% 97.32 KB 97.18 KB 29.78 KB 29.7 KB UMD_PROD
react-art.development.js -0.1% -0.1% 571.17 KB 570.62 KB 120.87 KB 120.79 KB NODE_DEV
react-art.production.min.js -0.2% -0.5% 62.34 KB 62.2 KB 19.05 KB 18.96 KB NODE_PROD
ReactART-dev.js -0.1% -0.1% 582.23 KB 581.47 KB 120.55 KB 120.41 KB FB_WWW_DEV
ReactART-prod.js 🔺+0.2% -0.1% 198.97 KB 199.33 KB 33.78 KB 33.76 KB FB_WWW_PROD

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactNativeRenderer-dev.js +0.1% 0.0% 703.67 KB 704.08 KB 150.6 KB 150.67 KB RN_FB_DEV
ReactNativeRenderer-prod.js 0.0% 0.0% 246.96 KB 247.05 KB 43.22 KB 43.23 KB RN_FB_PROD
ReactNativeRenderer-profiling.js 0.0% 0.0% 252.97 KB 253.01 KB 44.54 KB 44.55 KB RN_FB_PROFILING
ReactNativeRenderer-dev.js +0.1% 0.0% 703.58 KB 704 KB 150.57 KB 150.65 KB RN_OSS_DEV
ReactNativeRenderer-prod.js 0.0% 0.0% 246.97 KB 247.06 KB 43.22 KB 43.23 KB RN_OSS_PROD
ReactNativeRenderer-profiling.js 0.0% 0.0% 252.99 KB 253.03 KB 44.54 KB 44.55 KB RN_OSS_PROFILING
ReactFabric-dev.js +0.1% 0.0% 692.52 KB 692.93 KB 147.98 KB 148.05 KB RN_FB_DEV
ReactFabric-prod.js 0.0% 0.0% 240.25 KB 240.35 KB 41.96 KB 41.98 KB RN_FB_PROD
ReactFabric-profiling.js 0.0% 0.0% 245.54 KB 245.58 KB 43.3 KB 43.31 KB RN_FB_PROFILING
ReactFabric-dev.js +0.1% 0.0% 692.43 KB 692.84 KB 147.93 KB 148 KB RN_OSS_DEV
ReactFabric-prod.js 0.0% 0.0% 240.26 KB 240.35 KB 41.96 KB 41.97 KB RN_OSS_PROD
ReactFabric-profiling.js 0.0% 0.0% 245.56 KB 245.6 KB 43.3 KB 43.31 KB RN_OSS_PROFILING

react-test-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-test-renderer.development.js -0.1% -0.0% 585.7 KB 585.29 KB 123.96 KB 123.9 KB UMD_DEV
react-test-renderer.production.min.js -0.2% -0.2% 63.65 KB 63.52 KB 19.47 KB 19.42 KB UMD_PROD
react-test-renderer.development.js -0.1% -0.1% 581.33 KB 580.92 KB 122.83 KB 122.76 KB NODE_DEV
react-test-renderer.production.min.js -0.2% -0.3% 63.35 KB 63.22 KB 19.28 KB 19.22 KB NODE_PROD
ReactTestRenderer-dev.js -0.1% -0.1% 593.93 KB 593.31 KB 123.17 KB 123.07 KB FB_WWW_DEV
react-test-renderer-shallow.development.js -2.6% -2.9% 39.85 KB 38.82 KB 9.96 KB 9.67 KB UMD_DEV
react-test-renderer-shallow.production.min.js 🔺+0.3% 🔺+0.4% 11.7 KB 11.73 KB 3.59 KB 3.6 KB UMD_PROD
react-test-renderer-shallow.development.js -1.3% -1.7% 34.08 KB 33.62 KB 8.58 KB 8.44 KB NODE_DEV
react-test-renderer-shallow.production.min.js 🔺+0.3% 🔺+0.7% 11.89 KB 11.92 KB 3.7 KB 3.72 KB NODE_PROD
ReactShallowRenderer-dev.js -1.6% -1.7% 33.82 KB 33.27 KB 8.4 KB 8.25 KB FB_WWW_DEV

react-noop-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-noop-renderer.development.js +2.4% +1.8% 35.25 KB 36.1 KB 8.75 KB 8.91 KB NODE_DEV
react-noop-renderer.production.min.js 🔺+0.1% 🔺+1.0% 10.49 KB 10.5 KB 3.45 KB 3.48 KB NODE_PROD
react-noop-renderer-persistent.development.js +2.4% +1.8% 35.36 KB 36.22 KB 8.76 KB 8.92 KB NODE_DEV
react-noop-renderer-persistent.production.min.js 🔺+0.1% 🔺+0.9% 10.51 KB 10.52 KB 3.46 KB 3.49 KB NODE_PROD
react-noop-renderer-server.development.js 0.0% +0.1% 1.83 KB 1.83 KB 874 B 875 B NODE_DEV
react-noop-renderer-server.production.min.js 0.0% 🔺+0.2% 813 B 813 B 488 B 489 B NODE_PROD

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler.development.js -0.1% -0.1% 574.35 KB 573.79 KB 120.41 KB 120.31 KB NODE_DEV
react-reconciler.production.min.js -0.2% -0.5% 63.34 KB 63.2 KB 18.83 KB 18.74 KB NODE_PROD
react-reconciler-persistent.development.js -0.1% -0.1% 572.16 KB 571.6 KB 119.51 KB 119.41 KB NODE_DEV
react-reconciler-persistent.production.min.js -0.2% -0.5% 63.35 KB 63.21 KB 18.83 KB 18.74 KB NODE_PROD
react-reconciler-reflection.development.js -2.6% -2.5% 17.15 KB 16.7 KB 5.21 KB 5.08 KB NODE_DEV
react-reconciler-reflection.production.min.js 🔺+1.3% 🔺+1.9% 2.43 KB 2.46 KB 1.09 KB 1.11 KB NODE_PROD

react-is

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-is.development.js +4.8% +6.4% 8.36 KB 8.76 KB 2.5 KB 2.67 KB UMD_DEV
react-is.production.min.js 0.0% 🔺+0.1% 2.41 KB 2.41 KB 938 B 939 B UMD_PROD
react-is.development.js +5.0% +6.5% 8.17 KB 8.58 KB 2.46 KB 2.62 KB NODE_DEV

react-debug-tools

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-debug-tools.development.js +1.8% +2.6% 19.17 KB 19.52 KB 5.71 KB 5.86 KB NODE_DEV
react-debug-tools.production.min.js 🔺+5.0% 🔺+6.8% 5.8 KB 6.08 KB 2.35 KB 2.51 KB NODE_PROD

react-cache

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-cache.development.js +4.7% +5.0% 9.27 KB 9.71 KB 3.11 KB 3.26 KB UMD_DEV
react-cache.production.min.js 🔺+8.6% 🔺+10.2% 2.38 KB 2.59 KB 1.21 KB 1.33 KB UMD_PROD
react-cache.development.js +4.8% +5.1% 9.05 KB 9.48 KB 3.04 KB 3.19 KB NODE_DEV
react-cache.production.min.js 🔺+9.5% 🔺+11.3% 2.19 KB 2.4 KB 1.12 KB 1.25 KB NODE_PROD
ReactCache-dev.js +4.7% +6.6% 7.47 KB 7.82 KB 2.41 KB 2.56 KB FB_WWW_DEV
ReactCache-prod.js 🔺+6.5% 🔺+9.1% 5.17 KB 5.51 KB 1.63 KB 1.78 KB FB_WWW_PROD

create-subscription

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
create-subscription.development.js -5.7% -5.2% 8.03 KB 7.58 KB 2.77 KB 2.63 KB NODE_DEV
create-subscription.production.min.js 🔺+1.3% 🔺+1.7% 2.5 KB 2.54 KB 1.18 KB 1.2 KB NODE_PROD

scheduler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
scheduler-unstable_mock.development.js +2.8% +4.2% 17.3 KB 17.78 KB 3.98 KB 4.15 KB NODE_DEV
scheduler-unstable_mock.production.min.js 🔺+1.0% 🔺+1.8% 4.02 KB 4.06 KB 1.59 KB 1.62 KB NODE_PROD
SchedulerMock-dev.js +2.8% +4.3% 17.51 KB 18 KB 4.02 KB 4.19 KB FB_WWW_DEV
SchedulerMock-prod.js 🔺+1.2% 🔺+1.6% 11.86 KB 12 KB 2.43 KB 2.47 KB FB_WWW_PROD
scheduler-tracing.production.min.js 0.0% 🔺+0.3% 728 B 728 B 381 B 382 B NODE_PROD
scheduler-tracing.profiling.min.js 0.0% +0.1% 3.26 KB 3.26 KB 997 B 998 B NODE_PROFILING

jest-react

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
jest-react.development.js -7.8% -6.5% 6.94 KB 6.4 KB 2.5 KB 2.33 KB NODE_DEV
jest-react.production.min.js 🔺+1.3% 🔺+1.3% 2.54 KB 2.58 KB 1.28 KB 1.3 KB NODE_PROD
JestReact-dev.js -11.1% -9.4% 4.89 KB 4.35 KB 1.72 KB 1.55 KB FB_WWW_DEV
JestReact-prod.js 🔺+1.4% 🔺+1.9% 3.41 KB 3.46 KB 1.26 KB 1.28 KB FB_WWW_PROD

eslint-plugin-react-hooks

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
eslint-plugin-react-hooks.development.js +0.5% +1.0% 75.73 KB 76.11 KB 17.28 KB 17.45 KB NODE_DEV
eslint-plugin-react-hooks.production.min.js 🔺+1.8% 🔺+2.0% 20.01 KB 20.37 KB 6.92 KB 7.06 KB NODE_PROD
ESLintPluginReactHooks-dev.js +0.5% +1.0% 81.18 KB 81.56 KB 17.81 KB 17.98 KB FB_WWW_DEV

Generated by 🚫 dangerJS

@acdlite acdlite force-pushed the minify-normal-errors-too branch 5 times, most recently from d942f0e to ced6caa Compare March 9, 2019 03:46
@acdlite acdlite force-pushed the minify-normal-errors-too branch from acc207c to 7835fb0 Compare March 18, 2019 20:59
acdlite added 5 commits April 9, 2019 14:12
This updates our script to extract error messages from invariant calls
and strip them in production to also support Error constructors. As with
invariant, it converts them to use ReactError in development and
ReactErrorProd in production.

It supports both strings and template literals with interpolated values.
If it encounters an error constructor that contains unsupported syntax,
it will exit gracefully. In a next step, I will add a lint rule that
enforces error messages are minifiable.
I took this approach instead of failing at build time because

1. Better dev experience. The lint rule will warn you inside your
editor as you type, whereas a build time rule won't fail until you
run the tests or the build script.
2. Easier to opt out specific errors from the rule, like the ReactError
module, which intentionally uses a dynamic error message.
Some Babel plugins are only meant to run on source files, some only on
tests, and so on. We were using a single preprocessor and some
metaprogramming to determine which ones to run per file; I changed it
to use separate preprocessors per category instead.

The practical reason I made this change was so the error code script
does not run on test files.
@acdlite acdlite force-pushed the minify-normal-errors-too branch from 7835fb0 to 8fad8da Compare April 9, 2019 21:13
@acdlite acdlite changed the title Add support for normal errors to error code infra [Outdated; needs revision] Add support for normal errors to error code infra Jun 14, 2019
@Jessidhia Jessidhia self-assigned this Oct 7, 2019
@necolas necolas added the React Core Team Opened by a member of the React Core Team label Jan 8, 2020
@acdlite
Copy link
Collaborator Author

acdlite commented Jan 23, 2020

Closing because the code is outdated but we should still do this

@acdlite acdlite closed this Jan 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants