GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Update error minification script to support Error call expressions by acdlite · Pull Request #22428 · react/react Conversation
Collaborator
We use a script to minify our error messages in production. Each message is assigned an error code, defined in This enables us to write helpful error messages without increasing the bundle size. Right now, the script only works for So, I've updated the script to minify error constructors, too: Input: Error(`A ${adj} message that contains ${noun}`); Output: Error(formatProdErrorMessage(ERR_CODE, adj, noun)); It only works for constructors that are literally named Error, though we could add support for other names, too. As a next step, I will add a lint rule to enforce that errors written this way must have a corresponding error code. Test planI added Jest tests for the Babel transform. There was only a single place in our codebase where we used Error instead of Before: value = Error( (getComponentNameFromFiber(sourceFiber) || "A React component") + " suspended while rendering, but no fallback UI was specified.\n\nAdd a <Suspense fallback=...> component higher in the tree to provide a loading indicator or placeholder to display." ); After: value = Error( formatProdErrorMessage( 409, getComponentNameFromFiber(sourceFiber) || "A React component" ) ); Note: we should also strip all uses of
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
There was an error while loading. Please reload this page.
|
Comparing: 7d38e4f...2bcea20 Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: Expand to show
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
150afa1 to
599e1a1
Compare
495df2f to
b41dc1c
Compare
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
See https://github.com/facebook/react/pull/22428/files#r716105083. Since this message was never part of a public bundle we can remove it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Same here
Sorry, something went wrong.
There was an error while loading. Please reload this page.
b41dc1c to
c09d87d
Compare
There was an error while loading. Please reload this page.
|
Ironically the server build of React Fetch increased slightly in size because this message started being minified: but since it's the only error message in that package, the cost of the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
c09d87d to
d0b70c9
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Noticed this was being minified in jest-react but that's an internal module so there's no reason to. The extract-errors script must have picked this up at some point. Since it's not part of a public bundle we don't have to minify it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
d0b70c9 to
7553658
Compare
7553658 to
05726d7
Compare
bba6bb8 to
45a60e0
Compare
When this code was written, the error codes map (`codes.json`) was created on-the-fly, so we had to lazily require from inside the visitor. Because `codes.json` is now checked into source, we can import it a single time in module scope.
We use a script to minify our error messages in production. Each message is assigned an error code, defined in `scripts/error-codes/codes.json`. Then our build script replaces the messages with a link to our error decoder page, e.g. https://reactjs.org/docs/error-decoder.html/?invariant=92 This enables us to write helpful error messages without increasing the bundle size. Right now, the script only works for `invariant` calls. It does not work if you throw an Error object. This is an old Facebookism that we don't really need, other than the fact that our error minification script relies on it. So, I've updated the script to minify error constructors, too: Input: Error(`A ${adj} message that contains ${noun}`); Output: Error(formatProdErrorMessage(ERR_CODE, adj, noun)); It only works for constructors that are literally named Error, though we could add support for other names, too. As a next step, I will add a lint rule to enforce that errors written this way must have a corresponding error code.
This error message wasn't being minified because it doesn't use invariant. The reason it didn't use invariant is because this particular error is created without begin thrown — it doesn't need to be thrown because it's located inside the error handling part of the runtime. Now that the error minification script supports Error constructors, we can minify it by assigning it a production error code in `scripts/error-codes/codes.json`. To support the use of Error constructors more generally, I will add a lint rule that enforces each message has a corresponding error code.
45a60e0 to
2bcea20
Compare
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.