So if you don't know, when you use additional data, you only need to have SAS related data inside of additional data. So, for example, in variable CSS, it should be only SAS variables, SAS functions, and SAS mixins. And me, because I added CSS, it added for every component the CSS at the top of the component. So I went to work. I moved all root files in a global CSS file that I imported in index.html. And the problem went away. And to make matters even more embarrassing, this one fix saved us like 200K of our final JavaScript build.
Now, about bundle size, we kept adding features. So our bundle kept increasing and performance was degrading. So we decided to use the lazy of our main roots using React.lazy, like this. So what happens when you do this is if you go to a page, it will load that page-related code only when you click on the navigation. But the problem was that as soon as we did this, in production we started getting some errors, which is failed to import dynamic module error. Now, this was happening because every time we deployed, if there are people using the app and they click on the navigation, our deploy process deletes the old hash that the deploy is using for cache-busting purposes and updates it with a new one.
Now, Vite has a pre-load error event that you can listen to globally. And when this happens, it simply reloads the page and this worked 99% of the time. But for a pesky 1%, they were using old browsers or mobile Safari for some reason, it stuck them in an infinite loop. So we explored different solutions. And of course, the safest one was to not delete the old hash from the disk and keep one or two versions in prone so this doesn't happen. And this, again, worked for 99% of the time, but when we had API breaking changes, it made also the app crash, which we also didn't want. And eventually, we landed on our final solution where we kept both versions of the hash, but instead of being a random hash that Vite generates, we used our app's package version as the version number, as the hash. And then when we do a deploy, we have a service worker that actually runs in the background, checks for a new API version, and every time there's a new API version, it updates the source maps of the user's internal manifest.
Comments