The host application might have a different version of React. We would want some way of checking that those dependencies are compatible at build time. Then, automatic optin for non-breaking changes. This is the idea of, like, I have a header, it doesn't need any information, it's just a React component and the type is just, like, cool, it's a header, render it, it's going to show the header. Whenever someone change a copy inside the header, the color, whatever, the contract of that component doesn't change. So team that use the header should not have to do anything. If you refresh the page, you should see the new header when you push a new one.
Manual optin for breaking change means whenever a team, actually, that on the header, actually need to do something new to do that job. For example, we just translated, like, made our website internationalized and now the component need to know which language it need to display. Otherwise, it can't do the job anymore. Well, in that case, we'll need to communicate to the team that choose that component to be like, actually, no, please, you need to provide language as part of the contract to that component for me to do my job. And in that case, you do basically a new package version and ask teams to update manually and change the codebase because they actually need to change something in the codebase for the component to be able to work.
What does the architecture looks like? So, we have this amazing diagram that's, like, everybody's like, oh, my God, what is happening here? There's so many pink boxes. We'll go through them one by one. The first one, the host. So, the thing that's going to display that microphone. So, a remix app in this case. The second one is a tiny frontend. It's a piece of frontend, a header, a footer, some kind of component that's going to be consumed by the host. So, displayed inside the host application and composed of two folders, an app folder that contained the actual source of your React component and a contract, which is an NPM package that you're going to publish for people that want to consume that at runtime to be able to do so. And finally, because we're talking about deploying those bundles from this tiny frontend because we need to be able to change them, because not in the NPM package, they can change somewhere, they need to be somewhere to push those bundles to. And in this case, it's a small API built on Cloudflare and deployed on Cloudflare as a Cloudflare worker.
Cool. So, our example host, in this case, Remix, it's going to install the NPM package, which provides a method which is asynchronous, and when you call that method, it returns to you a React component that you can use in your application. When you call that method, what does it do? Well, it uses a tiny client library to call an API to get the latest version of the bundle. So, all the complexity of, like, how do I get a React component at runtime from a bundle that's deployed somewhere and everything, all of that is abstracted away in the library. So, when you build a new tiny frontend, you don't need to reinvent the wheel all the time and copy paste a lot of code. You can just have like basically everything is just abstracted away in a library that you use. So, whenever the team that has the tiny frontend, for example, the header team, have a new version of the header, they'll just, like, push to the repository, they'll have some kind of, for example, a GitHub action that's going to bundle the new component, and then deploy that bundle to this Cloudflare API. And it will, like, basically update the state there to say, this is now the new bundle.
Comments