Introducing React's Error Code System
facebook.github.io
facebook.github.io
While this looks useful, if `Foo` is an part of my application state I'm not too crazy about shipping that over to Facebook if I wanted to use this feature.
To clarify: the error message contains a link which goes to our GitHub pages site -- nothing is sent to any server automatically. You can always edit the URL if there's sensitive data in it for some reason.
You can also review the full source of our site or run it locally if you care to; it's all in the repo.
[1] https://github.com/facebook/react/blob/master/src/shared/uti...
[2] https://github.com/facebook/react/blob/master/docs/_js/Error...
Not sure if you missed spicyj's point or arguing that you yourself might not notice the sensitive data in the url.
If you - as the developer - need to inquire more about the error (say after reproducing it on production), you copy and paste the error url and remove the sensitive data before going to said url.
Even copying the error can be made a bit easier. Most (atleast FF and Chrome) consoles have the `copy` function which directly copies the passed string to clipboard. So when the error occurs, you can store it in an object in the global scope and the developer can just copy it with `copy(React.runtimeErrors.<errid>)` which is all autocompleted by the console anyways.
Now surely copy pasting secret stuff on another site is not very secure, but atleast it is not gonna be leaked to everyone in between the network from the url.
It's 4.5KB gzipped. All things considered this is insignificant to a normal react app.
This just adds extra overhead for everybody who tries to deal with those react errors in production (like for instance Sentry).
We thought this was a good compromise, but maybe we'll revisit in the future. Your feedback is valuable.
From @benvinegar's comments there (ex: https://github.com/facebook/react/issues/2686#issuecomment-2...) it sounded like the error code system would go at least most of the way towards solving your problem. Obviously the error message would not show up in Sentry automatically, but I figured that it would be a click away. I guess I must have misunderstood something along the line though.
If you're serving to mobile phones in third world countries [and you're concerned with React's size], then you can always NOT use React.
Apparently Facebook is not concerned with that, or doesn't consider it a problem for third world networks.
But for those people that complain about React's size and third world usage, they do know that there are tons of lighterweight options, right?
Hoping to see more awesome stuff from him!
It's a terrible precedent and lacks any sort of standard :-/ I'm not a fan of this sort of pattern spreading.
At that time, the size/parse time will have much greater impact because the total size of libraries will be smaller or unaffected.
At the same time it encourages libraries to put significant error messages in their code without fear of bloat which helps your customers in the end.
Personally, I hope everyone will follow.
If Sentry or others that understand this problem space better create a standard format, we would be happy to switch to that.
Everything have to start somewhere. :)
Edit: here's someone complaining about it: https://github.com/angular/angular.js/issues/6077
It is a strong statement that React cares strongly about my page weight, even as small as 3KB. At least the implied message it sends me:
1. I really should care about my page weight too.
2. React must really need every KB it currently uses. And if not, it will soon optimize away the bloat.
With the prevalence of npm and mini-libraries I'd be interested to see if the size of React could be cut down and put into optional components.
It's not a magic bullet, but it can go a long way in helping remove a ton of unused-for-your-use-case code in your production build.
For tree shaking to work, it must be possible to statically infer that some code is not part of the dependency graph of your application. Something like SVG support requires extensions to the virtual dom node structure that the renderer's visitor looks at, so it's quite difficult to make it into a hook and not lose performance to various overheads. It's also worth mentioning that over-modularizing can get boilerplatey (e.g. https://github.com/paldepind/snabbdom#inline-example)
There is lower-hanging, bigger-buck-for-your-bang, fruit if you're trying to fight page bloat.
[1] - https://github.com/facebook/react/blob/master/scripts/error-...
Another requirement would be that the URL on the server also does not change, otherwise the links from older react version would be broken.