-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
feat: mangle error codes to error indexes #3920
Conversation
Added mangleErrors babel script which converts error messages from strings to error code indexes.
Deploy preview for redux-docs ready! Built with commit 1cd8f07 |
Hey, this is pretty neat! And yes, saving 2.1K is totally worth it. First few questions off the top of my head:
Also paging @phryneas and @msutkowski here |
@markerikson Awesome! Putting my 2 cents to your points but I assume the folks you tagged will have some thoughts too!
|
So, at the risk of comment spam, I did a quick experiment with docusaurus and it is totally possible to do something with the error codes.... here's an example (excuse the lack of styling) if we just outputted all of them by enumerating over the generated json file: I just created a small React component in
|
Sweeeeet! Yeah, that looks like a good starting point. Seems like we ought to be able to build on that. Someone on Twitter was digging into how React implements things on their side: https://twitter.com/giovannibenussi/status/1320547654028431360 |
Yea, I was digging into that code earlier which is where I was saying "Just looked at the code for the redux site, it's VERY custom Gatsby code" in my previous comment. My stuff above with docusaurus is pretty similar to what they are doing. I think we could do something similar of linking to a page on the docs site, just would be slightly less savings in code as we'd have to add a function that includes the message with the link. So, depends on what we think would be the "best" option for consumers. |
Ok, last comment of the night! For the repos already using TSDX (Redux Toolkit for example), it's probably best to work with the build tool. This will require some refactoring to replace all throws with an invariant implementation. Seems like tiny-invariant (https://www.npmjs.com/package/tiny-invariant) would be a good choice to keep the bundle size small, or possibly keep a copy of an invariant function in each repo and strip it down even more? In either case, errors would be refactored:
If we want to explore this in Redux Toolkit, I'm happy to add to my todo list and give it a shot sometime this week. :) |
Looks like a very welcome contribution to me. |
Hi! I'm the guy from Twitter 😜
Basically you don't have to worry about data retrieval in the <ErrorDecoder
errorCodesString={data.errorCodesJson.internal.contentDigest}
location={location}
/> However, this works well because they retrieve this data once per build and not in real time. I'm not familiar with redux's docs nor your CI servers, but if you like react docs' solution, just out of my head I can think about copy the contents from |
Looks good to me as well! Regarding possibly switching to TSDX, redux exports an ESM browser build which is currently a small challenge to support with TSDX as shown in this PR: reduxjs/redux-toolkit#658. This was also recently referenced in this TSDX issue - outside of that, when I opened that PR all of the custom rollup configs redux uses basically match the TSDX defaults, so it should be pretty straightforward. |
We started the TS conversion before TSDX really took off, so it wasn't in the cards. I'd love to switch to it, but obviously that's outside the scope of this PR. I would like to incorporate this compressed error approach. However, it is technically a breaking change (for production builds, no less), so I don't think it's semver to do this in the 4.x branch. Let's keep this on master and a bonus for those upgrading. |
So then for next steps...
@markerikson Thoughts? 😄 |
Based on jaredpalmer/tsdx#759 (comment) and jaredpalmer/tsdx#912 (comment) there are some issues in TSDX (more specifically upstream in rollup) that will cause some issues in all redux repos. Seems like the error extraction isn't a well supported feature. |
@andrewmcgivery nice research. I'd say let's see if we can put together some kind of complete solution in this PR, including generating an appropriate docs page based on a JSON file extracted earlier in the docs build step. |
…d build to link to redux error page, styled error page and changed to only show error text for error passed in url.
@markerikson ok so some changes! Using a shared function that is injected in dynamically just like the React implementation, error messages now output a message with a link to the site with an error code in the URL:
Took some heavy inspiration from React's page and tried to make the styles match the docs page as much as possible, looks like this when you follow that URL: Worth mentioning, this is slightly less savings due to the function but still savings: Errors file is automatically updated during build process and the website pulls the error codes from it directly. Anything missing? :) EDIT: Seems to be some build issues with the website. Working through that. Edit 2: Fixed 😄 Edit 3: Apparently the latest VSCode update broke prettier so I had to run the formatter cause it was breaking the build. Fingers crossed it'll pass this time! |
@markerikson Sorry, I know you're busy with the doc rewrites and I don't want to be that guy that bumps a PR... I just don't know the proper protocol to ping you. 😨 |
Yeah, thanks for the ping, actually - I missed the last update here. A couple more questions:
Personally, I still think we ought to be able to do this for 4.x. @timdorr , I wouldn't see this as a "breaking" change per se, although I can understand why it could be viewed that way. Also, given that we have no concrete plans to release 5.0 any time soon, I'd see this as a net win - shrinking some byte size off the core lib. Say, 4.1.0? |
@markerikson Added the full list of codes to the page. Screenshots of light and dark themes: Regarding the UMD prod build, is there some way you'd prefer to verify this? I took a quick look through the minified source code and I do see the minified |
I could pull and build this myself, but don't feel like doing so atm :) I'll take your word for it for now. FWIW, I threw the question out on Twitter and over in Reactiflux. Some responses:
same person a minute later:
Someone else, on Twitter:
|
You can use the Netlify preview to see it in action: https://deploy-preview-3920--redux-docs.netlify.app/errors?code=5 |
That is slick. Well, I'm sold. Tim, thoughts? |
I think it looks pretty good. Any outstanding TODOs that I may have missed? |
MR is all good to go from my perspective! The only note I will add is I would be a little hesitant to switch all of the redux repos to TSDX unless there is a good reason to based on the issues around error extraction not working and it being extremely difficult to debug why. I'm sure TSDX is great if you're starting from scratch and don't want to deal with rollup configuration but I would argue if you've already got a config that is working, I don't see the benefit to changing that. Just my 2 cents. :) |
PR Type
Does this PR add a new feature, or fix a bug?
Feature (ish)
Why should this PR be included?
This small addition to the build script results in a savings of around 30% when minified/bundled.
Before/After of Redux.min.js:
Checklist
New Features
What new capabilities does this PR add?
Added mangleErrors babel script which converts error messages from strings to error code indexes per #3655.
For example:
Before:
After (with minify):
After (without minify):
What docs changes are needed to explain this?
May need a new doc around debugging in production but hoping the documentation king @markerikson has some ideas here :)
Outstanding Questions