<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Zsolt Burzas on Medium]]></title>
        <description><![CDATA[Stories by Zsolt Burzas on Medium]]></description>
        <link>https://medium.com/@burzas.zsolt?source=rss-43e1ae27ad58------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*S-TbZfbKnIvMoA0AR50EQQ.jpeg</url>
            <title>Stories by Zsolt Burzas on Medium</title>
            <link>https://medium.com/@burzas.zsolt?source=rss-43e1ae27ad58------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 05:03:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@burzas.zsolt/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A Module Federation Example for React]]></title>
            <link>https://levelup.gitconnected.com/a-module-federation-example-for-react-1fa29d6ac07b?source=rss-43e1ae27ad58------2</link>
            <guid isPermaLink="false">https://medium.com/p/1fa29d6ac07b</guid>
            <category><![CDATA[module-federation]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[micro-frontends]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Zsolt Burzas]]></dc:creator>
            <pubDate>Wed, 28 Oct 2020 19:27:18 GMT</pubDate>
            <atom:updated>2020-10-28T19:27:51.509Z</atom:updated>
            <content:encoded><![CDATA[<h4>Micro Frontends with Module Federation</h4><p>Check out a React micro frontend solution implemented with module federation</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0OZzs6S9bhrQeHA9NlSGbw.png" /></figure><h3>Previously on…</h3><p>The base of this example is another <a href="https://levelup.gitconnected.com/a-micro-frontend-solution-for-react-1914b19663b">article</a> I wrote a little while ago showcasing micro frontends with React. In a few words, the app is a French Bulldog accessory web shop where the host application is a simple React app with a product list and a cart page. These two routes are rendering a product and a cart micro frontend. Check the <a href="https://levelup.gitconnected.com/a-micro-frontend-solution-for-react-1914b19663b">story</a> out for more details. In this writing, I would like to present a possible implementation of micro frontends using module federation and compare the two solutions from several perspectives. Here is the repo below if you would like to check out the exampe in details:</p><p><a href="https://github.com/burzaszsolt/react-module-federation">burzaszsolt/react-module-federation</a></p><h3>Module Federation</h3><p>You may have never heard of this Javascript architecture because it’s a pretty new feature introduced in Webpack 5. The best description comes from the inventor <a href="https://medium.com/@ScriptedAlchemy">himself</a>:</p><blockquote>Module federation allows a JavaScript application to dynamically load code from another application — in the process, sharing dependencies, if an application consuming a federated module does not have a dependency needed by the federated code — Webpack will download the missing dependency from that federated build origin.</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FfDzM81OYrNjJC%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FfDzM81OYrNjJC%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FfDzM81OYrNjJC%2F200.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="258" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8a870bb9e03ee3a274ab36c808a6aa2/href">https://medium.com/media/b8a870bb9e03ee3a274ab36c808a6aa2/href</a></iframe><p>Sounds cool, right? If you would like to learn more about the topic read <a href="https://medium.com/swlh/webpack-5-module-federation-a-game-changer-to-javascript-architecture-bcdd30e02669">this story</a> first and come back. Now let’s see what changes I had to do in order to use module federation as the base of my app’s micro frontend architecture.</p><h3><strong>Solution</strong></h3><h4>Remotes</h4><p>To turn my micro frontends into remote apps, all I had to do was adding the ModuleFederationPlugin to my webpack config file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b2803d185fb990f8783b3a34214dc5d6/href">https://medium.com/media/b2803d185fb990f8783b3a34214dc5d6/href</a></iframe><p>In the plugin configuration, I defined ProductService as a component I would like to expose from this app so it can be consumed in other applications. Another important part of the config is the shared object where I could list all the dependencies to share between the host and remote.</p><h4>Host</h4><p>With these changes in place, I had a remote ready to be consumed. All I had to do is changing the host in three small steps so it can render the micro frontend. The first step was to change the webpack config:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/78336b6c8ddd0f1357b8dafb6f55d0c0/href">https://medium.com/media/78336b6c8ddd0f1357b8dafb6f55d0c0/href</a></iframe><p>In the ModuleFederationPlugin config, I defined the products and cart micro frontends as remotes. This allows me to access them in my components.</p><p>The second step was to add the remoteEntry.js from all remotes in my index.html . These are small bundles (few kB) containing minimal information about the modules.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8859428f2caba6554d08cf198698650d/href">https://medium.com/media/8859428f2caba6554d08cf198698650d/href</a></iframe><p>The third (my favorite) step was to render the remote in the host:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2b6794860a5cfe4c3443a56ae87c329/href">https://medium.com/media/c2b6794860a5cfe4c3443a56ae87c329/href</a></iframe><p>I could lazy import the ProductService from the mfProducts remote and render it in my Products component and that’s it. It is this simple. 🎉🙌</p><h4><strong>Bi-directional hosts</strong></h4><p>As you may noticed, I also expose and add the host app as remote in the micro frontends. This means that all my apps are both <strong>consumers</strong> and <strong>remotes</strong> which makes them something called<strong> bi-directional hosts</strong>. Doing this allows me to render the host app in my micro frontends so I can easily develop them as if they were one application. The entry point of my micro frontends is the index.js that renders the component below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e857b33dcf001dbc3cdc503cdf3b140/href">https://medium.com/media/0e857b33dcf001dbc3cdc503cdf3b140/href</a></iframe><p>I can render the exposed host app the same way I do with the remotes. The result is that it doesn’t matter which app I’m looking at they all look the same.</p><h3>Conclusions</h3><p>In this chapter I would like to observe some aspects about my two implementations of the same application to see what are the differences between them.</p><h4>Exposing the apps</h4><p>In my previous example, I created a library from each micro frontend that were accessible in other applications through the window object. This library contained some methods that I implemented to render or unmount the micro frontend. It was not a complicated solution but with the ModuleFederationPlugin it is even simpler.</p><h4>Consuming the apps</h4><p>I was amazed how easily I could use the remotes in the host. Previously I created a custom useMicrofrontend React hook in order to dynamically load the micro frontend bundles into the application. With module federation it is supported by default.</p><h4>Performance</h4><p>This is one of the strongest advantages of module federation. By sharing the dependencies, the bundle sizes are reduced a lot. With the previous implementation, navigating to the cart page resulted in ~2.3MB of downloaded data which is the bundle size of the cart micro frontend (development build). Total transferred data with module federation for the same page was only ~700kB. It is a huge difference even in such a small application.</p><h4>Development</h4><p>In my first example, I could run each micro frontend as an independent application but to integrate them into the host app I had to rebuild them every time I changed something. With the bi-directional host implementation I could check every change I made in any app right away and test how it integrates into the whole app. This makes development more comfortable and efficient while keeping the advantages of micro frontends.</p><p>To sum it up, I love how module federation works and it is great to see how it solved some disadvantages of using micro frontends. I believe this is the way forward and it will change how we develop web applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1fa29d6ac07b" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/a-module-federation-example-for-react-1fa29d6ac07b">A Module Federation Example for React</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Micro Frontend Solution for React]]></title>
            <link>https://levelup.gitconnected.com/a-micro-frontend-solution-for-react-1914b19663b?source=rss-43e1ae27ad58------2</link>
            <guid isPermaLink="false">https://medium.com/p/1914b19663b</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[micro-frontends]]></category>
            <dc:creator><![CDATA[Zsolt Burzas]]></dc:creator>
            <pubDate>Tue, 09 Jun 2020 06:33:57 GMT</pubDate>
            <atom:updated>2020-10-28T20:26:02.151Z</atom:updated>
            <content:encoded><![CDATA[<p>Learn about a possible implementation of micro frontends with React through a simple web store application</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z6fvCk9Vk8t7oKkpQ82mKw.png" /></figure><p><em>*** Update *** <br></em>I wrote another article about the same example using module federation. Check it out for a different approach. 👇🏼</p><p><a href="https://levelup.gitconnected.com/a-module-federation-example-for-react-1fa29d6ac07b">A Module Federation Example for React</a></p><h3>What is this story about?</h3><p>I would like to present an example application I’ve created to showcase micro frontends with React. There are plenty of introductory articles discussing the pros and cons, so in my example I would like to focus on implementation only. For those who are not familiar with the concept, I placed some links at the <a href="#77e8">bottom</a> with more information on the subject. Check them out and come back. 😉</p><h3>Recap micro frontends in a few words</h3><p>It’s an architectural concept to build smaller applications that can be developed, tested and deployed independently instead of having a monolith. These apps then can be combined using several different techniques. In this article, I would like to present one possible way to build a single page React application with micro frontends.</p><h3>The example</h3><p>I’ve created a <a href="https://github.com/burzaszsolt/react-micro-frontends">repository</a> on GitHub so you can check out the code in detail. To sum it up in a few words: the app is a really simple French Bulldog accessory web shop which lists some products displaying cute frenchies and there is a cart page to list the products waiting for being “purchased”. I’ve also implemented some functionality to add, modify, or delete these items.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*PAyX19OSZDFJ13SLSuOCsQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cJxockfLiJg37PCvwd0xrw.png" /><figcaption>home page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eELUiEGkICpZWiezvnV6RQ.png" /><figcaption>cart page</figcaption></figure><h3>Structure</h3><p>The example consists of four parts:</p><ul><li>host app</li><li>products micro frontend</li><li>cart micro frontend</li><li>backend</li></ul><p>The host app is a React application that acts as the frame for the web shop. The products micro frontend is rendered on the home page which will display the items. The cart button appears on the top bar of the host app redirecting to the cart page. The cart micro frontend is rendered on this route. It is responsible for displaying the list of products in the cart. All of them are connected to the “backend” which is basically a fake REST API created with the <a href="https://github.com/typicode/json-server">json-server</a> package. Now that we have a brief view of the example, let’s have a look at some code. 🤓</p><h3>Solution</h3><h4>Micro frontends</h4><p>In my example, each micro frontend can be run as an independent application or can be built to behave as a micro frontend. To achieve this, I used <a href="https://webpack.js.org/">webpack</a> to create separate configurations with different entry points for each behavior. When running it independently, I use the <a href="https://github.com/burzaszsolt/react-micro-frontends/blob/master/mf-products/src/index.js">index.js</a> as an entry point which will render the application in a plain old React way and the app will be hosted by <a href="https://www.npmjs.com/package/webpack-dev-server">webpack-dev-server</a>. However, when building as a micro frontend, a different file is used, called microfrontend.js. This is where the magic happens so let’s have a look at it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/57fe2b49811bcaabbf478b24c606809c/href">https://medium.com/media/57fe2b49811bcaabbf478b24c606809c/href</a></iframe><p><strong>render()</strong></p><p>This method renders the App into the DOM in the container identified with the containerId param and passes all the data as props to the App.</p><p><strong>unMount()</strong></p><p>As its name implies, this function is responsible for removing the mounted App from the DOM.</p><p><strong>subscribe()</strong></p><p>The subscribe method registers event listeners on the window to handle custom events as these will be the common way of communication between the host and the micro frontends.</p><p><strong>unSubscribe()</strong></p><p>This function removes the registered event listeners from the window.</p><p><strong>customEvents</strong></p><p>It is an object holding the custom events that can be dispatched from a micro frontend.</p><p>As a result of the webpack build, a bundle file will be created containing a library that can be accessed through the window when used in other applications. In my example, these are called mfCart and mfProducts. Check out this <a href="https://github.com/burzaszsolt/react-micro-frontends/blob/master/mf-products/build/webpack.build.config.js">build config</a> for more details.</p><h4>Host</h4><p>Now let’s see how to use these libraries in the host application. We have a single javascript file from the micro frontend build. The question is how to add this bundle to the host application to access the micro frontend and it’s methods. In the example, I’ve created a custom React hook for this, called useMicrofrontend.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/440c4269dfd355c87642b351ee462607/href">https://medium.com/media/440c4269dfd355c87642b351ee462607/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*-py8Vq9kGV2N5FWqDAEgZw.jpeg" /></figure><p>So what happens here?</p><ul><li>The hook receives two parameters, id and url.</li><li>Checks if the script has already been added to the DOM and skips loading it again.</li><li>Creates a &lt;script&gt; tag with the provided params and appends it to the &lt;body&gt; of the DOM.</li><li>It will return with an object indicating if the resource is loaded and with the micro frontend itself once it is available though the window object.</li></ul><p>Important to notice that this way the bundles are dynamically loaded to the page. It means that the cart micro frontend in the home page won’t be loaded to avoid unnecessary downloads on the client side.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*eWP5DEPmWGAwNniOOh5QJA.png" /><figcaption>home page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*99C2me2h5P9B9Nih5t2KXg.png" /><figcaption>after navigating to cart page</figcaption></figure><p>Now let’s check out this custom hook in action.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e2ba13d2cdb4c0d41cd975cb71358f52/href">https://medium.com/media/e2ba13d2cdb4c0d41cd975cb71358f52/href</a></iframe><p>At first look, one could say that it only renders a &lt;div&gt; with some id but there is a bit more going on here. The useMicrofrontend hook on line 10 starts loading the bundle for mfProducts.</p><ul><li>While it is loading, the component won’t render anything.</li><li>If the bundle is loaded but the micro frontend is still not available, the component will display an error message.</li><li>The best scenario is that the script is loaded and the micro frontend is available. In this case, the render method of the mfProducts can be accessed and called with two parameters: the id of the div rendered by the Products component and some data I will cover later. As a result, the products micro frontend will be mounted into that div. 🎉🙌</li></ul><h4>Communication</h4><p>There are two icons in the top bar of the host application: one displaying how many products are in the cart and for navigating to the cart page, the other is for switching between light and dark theme.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_ervMKQ1ibuCyG7cXc_f0w.png" /><figcaption>top bar</figcaption></figure><p>The question is how the cart badge can be updated if the products micro frontend handles adding products to the cart? This is where using <a href="https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent">CustomEvent</a> comes into play. By clicking the cart icon on a product card, a request is sent to the json-server. If the request is successful a custom event is dispatched from the products micro frontend indicating that a product was added to the cart. Below is the CartBadge component that listens to that custom event and updates it’s state accordingly.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6bcf7ac69010baeb27b055cdf5a93861/href">https://medium.com/media/6bcf7ac69010baeb27b055cdf5a93861/href</a></iframe><p>In this component, the custom hook can be used again to get the products micro frontend. It doesn’t need to be rendered this time, instead an event listener is attached to the window by calling the subscribe method from mfProducts. As a cleanup for the useEffect hook, that event listener is removed by the unSubscribe function. The type of the custom event also comes from mfProducts so I can make sure to listen to the right event.</p><p>Now let’s see an example for communication from the host app towards the micro frontends. I used <a href="https://material-ui.com/">Material-UI</a> for building and styling components. This library provides a simple way to use light and dark theme with the <a href="https://material-ui.com/styles/api/#themeprovider">ThemeProvider </a>component. All I need to do is passing an object with the styles for each theme to this component and wrap my app in it. Sounds pretty simple, right? However, most things are rendered by the micro frontends which are out of scope for the ThemeProvider. Then how to apply the same theme for them? When rendering the micro frontends in the host application, the selected theme is passed to the render method. Each micro frontend has its own ThemeProvider that is initialized with the theme from the host app. It is still simple enough but what happens if I switch theme in the host application by clicking the button in the top bar? Well, in some cases, especially when the micro frontend has its own state, it would be a poor solution to re-render the whole micro frontend. So instead of doing that, a HOST_THEME_CHANGED custom event is dispatched with the selected theme from the host application. The micro frontends can listen to this custom event and feed their ThemeProvider with the received data.</p><h3>Sum up</h3><p>With the <a href="https://jaystack.com/">JayStack</a> team we are working on an international product for more than one year now and the example is based on the experiences from this project. We found it pretty simple to work with micro frontends using this configuration and I hope this example helps if you are interested in using them with React. I’ve tried to cover most of the stuff but if you have any questions check out the <a href="https://github.com/burzaszsolt/react-micro-frontends">repository</a> or leave a comment.</p><h3>More…</h3><p>Here are some useful links about micro frontends if you would like to learn more about them.</p><ul><li><a href="https://martinfowler.com/articles/micro-frontends.html">Micro Frontends</a></li><li><a href="https://micro-frontends.org/">Micro Frontends</a></li><li><a href="https://medium.com/stepstone-tech/microfrontends-extending-service-oriented-architecture-to-frontend-development-part-1-120b71c87b68">Microfrontends — part 1: extending service-oriented architecture to frontend development</a></li><li><a href="https://hackernoon.com/understanding-micro-frontends-b1c11585a297">Understanding Micro Frontends | Hacker Noon</a></li><li><a href="https://skilled.dev/">Coding Interview Questions + Land Your Dev Job | Skilled.dev</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1914b19663b" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/a-micro-frontend-solution-for-react-1914b19663b">A Micro Frontend Solution for React</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>