<?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 Federico Zivolo on Medium]]></title>
        <description><![CDATA[Stories by Federico Zivolo on Medium]]></description>
        <link>https://medium.com/@FezVrasta?source=rss-d9eefdd62ed7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*q4oPq68S89hqJtwF.jpeg</url>
            <title>Stories by Federico Zivolo on Medium</title>
            <link>https://medium.com/@FezVrasta?source=rss-d9eefdd62ed7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 22:18:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@FezVrasta/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[Service Worker updates and error handling with React]]></title>
            <link>https://medium.com/@FezVrasta/service-worker-updates-and-error-handling-with-react-1a3730800e6a?source=rss-d9eefdd62ed7------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a3730800e6a</guid>
            <category><![CDATA[service-worker]]></category>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Federico Zivolo]]></dc:creator>
            <pubDate>Fri, 02 Aug 2019 13:34:42 GMT</pubDate>
            <atom:updated>2019-08-02T13:36:03.329Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PTk_M3iaiktQmzvTCnH5vw.jpeg" /></figure><p>I recently worked to improve the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API">Service Worker</a> my team and I use in our React application. In this article, I’ll outline my learnings from the exercise, and some solutions to the problems we faced.</p><h3>Our setup</h3><p>At Quid, we rely on <a href="https://facebook.github.io/create-react-app/"><em>Create React App</em></a> to handle most of our products. We mostly rely on its default configuration. When we do need to diverge from the defaults, we prefer <a href="https://github.com/timarney/react-app-rewired">react-app-rewired</a> and <a href="https://github.com/arackaf/customize-cra">customize-cra</a> to tweak the configuration to fit our needs.</p><p>In most cases, our customizations are limited to adding:</p><ul><li>Our custom ESLint configuration;</li><li>The addBundleVisualizer plugin from customize-cra to help us analyze our bundle;</li><li>The adjustWorkbox plugin for tweaking the workbox navigateFallbackBlacklist to exclude some API endpoints which we use;</li></ul><p>The following examples and considerations assume you are using <em>Create React App</em> or a compatible solution. Also, it’s assumed that you are already familiar with the basic Service Worker concepts.</p><h3>What we wanted</h3><p>For a long time we kept our Service Worker enabled, but with the skipWaiting option on, this was a big source of frustration for our users.<br>If a new update was deployed <strong>while the users were using the application</strong>, it could break.</p><p>We wanted to make the user experience better by providing an update button to let our users update when they felt ready.</p><h3>Let’s get to work!</h3><p>To achieve this, we removed the skipWaiting option and added some code to detect when an update was available, and consequently show the update popup.</p><p>First thing I did was to hook into the onUpdate callback to get notified when a new Service Worker version was available.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3aa9efd9415f5206187f7d02365574a/href">https://medium.com/media/b3aa9efd9415f5206187f7d02365574a/href</a></iframe><p>With the above code, we can get notified when a new version of our application is available, and with the waitingServiceWorker content we are able to trigger the actual update by running:</p><pre>waitingServiceWorker.postMessage({ type: &#39;SKIP_WAITING&#39; });</pre><p>We could rewrite this as a custom React Hook to make it easier to use it in our codebase:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15d45f2bc7cff17b765372c9b7451784/href">https://medium.com/media/15d45f2bc7cff17b765372c9b7451784/href</a></iframe><p>With the above code, we are able to listen to service worker updates and trigger an update when the user clicks a button bound to the updateAssets function.</p><p>Let’s see it in action by creating some UI to trigger the code outlined above.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b9bcc0cbe47f77e0be3a723b4364df23/href">https://medium.com/media/b9bcc0cbe47f77e0be3a723b4364df23/href</a></iframe><h3>Handling edge cases</h3><p>We have one last problem to deal with. What happens if you ignore the update button and close, and then reopen, the application?</p><p>At the moment, the update button won’t be displayed ever again, leaving the user stuck with an old version of our app forever.</p><p>To address this issue, we need to update the registerValidSW function provided by Create React App in <a href="https://github.com/facebook/create-react-app/blob/v3.0.1/packages/react-scripts/template/src/serviceWorker.js#L57">src/serviceWorker.js</a>. Luckily we don’t need to eject, or use react-app-rewired for this!<br>We just need to expose an additional callback there, we’ll add the following code right after we obtain the registration object to add support for it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0f0a5fba68d143ebb2a270c2d21afdce/href">https://medium.com/media/0f0a5fba68d143ebb2a270c2d21afdce/href</a></iframe><p>Now we can update our custom Hook to register to this new callback. To save space, I’ll just share the changed code in serviceWorker.register:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8043a34a0e92d18a71aa8b9335f34cb3/href">https://medium.com/media/8043a34a0e92d18a71aa8b9335f34cb3/href</a></iframe><p>Now whenever the user opens our app, and an update has been downloaded and waiting to be installed, the same update popup will be displayed.</p><h3>Uncaught (in article) Error: [Object What?]</h3><p>With the solutions provided above you should be able to address all your Progressive Web App update needs, but there’s one last thing (and it’s not a good one!).</p><p>One of the most dangerous peculiarity of cache-first approach in Service Workers is the possibility to ship some broken code, and not be able to have your users receive your fix because the app is so broken that even the update process can’t run properly.</p><p>You can add a lot of error handling inside your React application, especially if you add an <strong>error boundary</strong> around your main component, but is it enough?</p><p>React’s <strong>componentDidCatch doesn’t catch all the possible errors</strong> generated by your application, and will do nothing if a 3rd party dependency introduces a critical bug.</p><p>To make sure our users never end up with a broken Service Worker cache and are always able to get the most updated version of it, we implemented a <strong>global error handler</strong> to catch any possible error we may not handle.</p><p>This error handler, internally called apocalypseHandler, will unregister the service worker if it finds a newer version is available, and then reload the page so that the browser is able to start afresh. We may attempt to update the service worker rather than unregister it, but something may be broken in the update process itself, so we don’t want to rely on any code external to our error handler.</p><p>We want to execute the code below as soon as possible, before we even attempt to render our application or run any other code. This minimizes the chances of our event handler failing to register due to prior errors.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6dc78760455da4c4429a9707298ad199/href">https://medium.com/media/6dc78760455da4c4429a9707298ad199/href</a></iframe><h3>That’s all folks!</h3><p>By handling background updates and making sure we don’t saddle our users with a broken version of the app, we’ve made our app a delight to use — both for our users and our developers.</p><p>If you have any other suggestions to improve this setup, please let me know in the comments!</p><p>Special thanks to <a href="https://medium.com/u/413e46919df6">Kumar Harsh</a> which helped me by proof reading this article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a3730800e6a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I managed to create a powerful positioning system]]></title>
            <link>https://medium.com/@FezVrasta/popper-js-v1-5e8b3acd888c?source=rss-d9eefdd62ed7------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e8b3acd888c</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Federico Zivolo]]></dc:creator>
            <pubDate>Fri, 06 Jan 2017 12:43:06 GMT</pubDate>
            <atom:updated>2018-11-27T15:58:18.702Z</atom:updated>
            <content:encoded><![CDATA[<figure><a href="https://popper.js.org/"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JNqJVzA-LwKpQ9fldiT5Lg.png" /></a></figure><p>This is an introduction post about the new major release of <a href="https://popper.js.org/">Popper.js</a>, if you don’t care about its history, jump to the “<a href="#0f0b">Popper.js v1</a>” section.</p><p>In the past, I spent several hours writing the same code over and over to position my tooltips and popovers inside web applications. Every time I worked on a new project, there were different necessities on how the elements should be positioned on the screen according to different environmental factors.</p><p>I reached the apex while I was working on a big Ember.js application that thanks to some bad UX decisions, wanted to show a tooltip or a popover on almost any element you hovered.</p><p>In such a code base, we started forking the tooltip system of Bootstrap 3, and incrementally hacked to add new features.</p><p>An important requirement was the ability to position a tooltip <strong>without having to move its DOM node as a direct child of </strong><strong>body</strong>, this is because with the ancient version of the framework we used would have broken the whole app.</p><h3>Finding an existing solution</h3><p>After almost a year working on this project and maintaining our custom implementation, I decided to switch to <a href="http://tether.io/">Tether</a>, since it seemed very powerful and stable.</p><p>Unfortunately, after having played with it for several hours, <strong>its limitations began to emerge</strong>. It automatically manipulated the DOM node, moving it as a direct child of body. It added classes and inline styles without ways to control them. It also lacked some core features we needed from a positioning engine and the performance was not optimal.</p><p>I spent a bunch of hours digging through GitHub in search for alternatives, but <strong>I literally found nothing</strong>. It seemed like nobody ever needed a library like that, or that nobody managed to create one good enough to be released.</p><p>I decided to dedicate a weekend to rewrite our whole positioning engine from scratch. The result was <a href="https://popper.js.org/"><strong>Popper.js</strong></a><strong>, an open source JavaScript library</strong> that worked pretty well on all the cases we faced in our app.</p><h3>Popper.js v0</h3><p>In its infancy, the library was just a single Javascript file written with several functions, focusing on keeping it small and lightweight.</p><p>There were some automated functional tests, but they didn’t cover the countless use cases.</p><p>I wanted to make it easily extensible, so <strong>I based it on a middleware system</strong>. The idea was to compute the position of the element and so let the middlewares take care to modify it according to the requirements.<br>For example, once it has the position of the popper and the defined boundaries; a modifier can detect if the popper will overflow and flip its placement to avoid to being cut off.</p><p>After the release I got some awesome feedback from the community and some great people helped me fix several bugs and introduce new features.<br>Some big companies like <strong>Atlassian and Microsoft</strong> started using it and were able to contribute to the source code and introduce new features like the support for <strong>shadow DOM</strong>.</p><p>While working on it, I realized that we needed a better code structure to be able to maintain it effectively.</p><p>This is where the development of version 1 started.</p><h3>Popper.js v1</h3><p>To organize the code base, I decided to switch to ES6 modules.<br>I added <strong>Rollup</strong> as code bundler and <strong>Babel</strong> as a transpiler, I also moved the automated tests from a headless Chrome setup to a <strong>SauceLabs cross-browser test suite</strong>.</p><p>During the development, I divided the functions and the modifiers/middlewares in their own files to be able to reuse them across the library. This helped to reduce the size since it allowed me to reuse much more code than previously.</p><h3>The update process</h3><p>I also refactored the whole update process, which is the action that gets called every time Popper needs to update the position of an element.</p><p>This process gets called on each frame, so it has to work at 60fps to keep the experience fluid. To make it possible, the whole process must be lean and <strong>avoid to access to the DOM if not strictly necessary</strong>.</p><p>This is how it works:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*mmBrtw-VrWjeBfEE6mUxSg.png" /><figcaption>Me trying to draw a flowchart. Disclaimer: colors are completely random</figcaption></figure><p>We managed to use as little as <strong>0.5ms for each frame</strong><em> (on my 2015 MacBook)</em>. We throttle it to avoid useless computations that would get ignored by the browser if executed more than once per frame. This makes it possible to compute the position of a popper during the scroll of the page or an animation without lag.</p><p>Below you can find a capture I did while I was scrolling the container up and down several times repeatedly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KRvUlQxTsDiKEOgFZqhIFQ.png" /><figcaption>Timeline captured during intensive scrolling, pure art, I know 😎</figcaption></figure><p>I’m very satisfied by the result!<br>Just 102.2ms used on a total time of 2.86 seconds, only 25ms spent during rendering and 27ms during painting.</p><h3>Reducing the library size</h3><p>Another important point I always wanted to keep in mind is the size of the library. Popper.js v1, without the built-in modifiers, weights just ~10kB minified. When it gets gzipped, the weight goes down to 3.76kB!</p><p>If we add the built-in modifiers, which add a lot of additional features to the core, we reach ~17kB minified, and just <strong>5.83 kB once gzipped</strong>. That’s pretty impressive, considering that Tether weights 25kB minified and 7.52kB gzipped supporting way less features.</p><p>To make sure the minified builds weighed as little as possible, <strong>I switched from Uglify to Babili</strong>. This made possible to squeeze every bit during the minification process.</p><h3>Demo time!</h3><p>After all these words, below you can finally find a demo of Popper.js in action.</p><p>This is an animated SVG created by <a href="https://twitter.com/sarah_edo">Sarah Drasner</a>, I added a tooltip below the pendulum to show you how it handles the situation. In this case the tooltip element is in a different context from the one of the pendulum, this means that the position is completely computed by Popper.js without any help from CSS.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2FFezVrasta%2Fembed%2Fpreview%2FEZjYWp%3Fheight%3D600%26amp%3Bslug-hash%3DEZjYWp%26amp%3Bdefault-tabs%3Dhtml%2Cresult%26amp%3Bhost%3Dhttp%253A%252F%252Fcodepen.io%26amp%3Bembed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2FFezVrasta%2Fpen%2FEZjYWp&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fm.cdpn.io%2Fscreenshot-coming-soon-small.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e30bebe00c4569a9dd49c64b315f467/href">https://medium.com/media/8e30bebe00c4569a9dd49c64b315f467/href</a></iframe><h3>React, Vue.js &amp; co.</h3><p>While I worked on the new release, I changed my job position, from Ember to a React code base (thank god!).</p><p>This allowed me to understand problems that Popper.js needed to take in account in order to <strong>support React or any other view library</strong> that wants to directly control the DOM manipulation.</p><p>With this in mind, Popper.js v1 now concentrates all the DOM manipulations into a single modifier, the applyStyle one.<br>This makes it possible to disable and replace it with a version compatible with React or any other view library.</p><p>I wanted to have some examples ready for the launch of the new version, so I asked <strong>Travis (</strong><a href="https://twitter.com/souporserious"><strong>souporserious</strong></a><strong>) Arnold</strong>, the author of <a href="https://github.com/souporserious/react-tether">react-tether</a> to take a look at Popper.js and consider to develop a wrapper around it like he did with Tether.<br>He was very impressed by Popper and decided to create <a href="https://github.com/souporserious/react-popper">react-popper</a> , it’s still in early stage but I count to see great progresses now that Popper.js v1 has been officially released!</p><p>In the <a href="https://github.com/FezVrasta/popper.js/#react-vuejs-angularjs-emberjs-etc-integration">README</a> of Popper.js you can find a section where I collected the libraries that allow you to use it in various frameworks and libraries, feel free to contact me if you created one and you want to see it listed there!</p><p>I really hope you will like what we did with <a href="https://github.com/FezVrasta/popper.js">Popper.js</a>, I’m sure it will save a lot of time to a bunch of Front-End Developers and I hope to see new tooltip and popover libraries based on it that will finally be able to focus on the features they want to add instead of trying to reinvent the wheel every time.</p><p>I’m eager to read your feedbacks in the comments!</p><p>Thanks <strong>Travis Arnold </strong>for having helped me with the review of this article.<br>Thanks <strong>Sarah Drasner</strong> for the original animated SVG.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e8b3acd888c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to maintain a healthy issues list]]></title>
            <link>https://medium.com/@FezVrasta/how-to-maintain-an-healthy-issues-list-4fc8efa1b202?source=rss-d9eefdd62ed7------2</link>
            <guid isPermaLink="false">https://medium.com/p/4fc8efa1b202</guid>
            <category><![CDATA[github]]></category>
            <category><![CDATA[open-source]]></category>
            <dc:creator><![CDATA[Federico Zivolo]]></dc:creator>
            <pubDate>Sun, 01 Jan 2017 14:52:42 GMT</pubDate>
            <atom:updated>2018-08-16T08:57:44.599Z</atom:updated>
            <content:encoded><![CDATA[<p>Maintain an open source project can be hard, being good coders isn’t enough, you must also be organized to manage the community around the project.</p><p>So far, I created two projects on GitHub with more than 9000 ★s (<a href="https://github.com/FezVrasta/bootstrap-material-design">+19.000</a> and <a href="https://github.com/FezVrasta/popper.js">+9.000</a>), they both started as simple projects without particular claims, but fastly grew up reaching these numbers.</p><p>To make your project grow, you must listen to your users and address the problems and concerns they rise.<br>This can be particularly difficult if the list of issues grows uncontrollably. To avoid this problem you have to define some rules, and enforce them.</p><h3>Issues template</h3><p>First, create a .github/ folder, and inside it create an ISSUE_TEMPLATE.md and a PULL_REQUEST_TEMPLATE.md. These files <a href="https://github.com/blog/2111-issue-and-pull-request-templates">will give you the ability to provide templates</a> that the users will have to read and complete in order to send an issue or a PR.</p><p>To make the issues template useful, an important thing is to <strong>require the user to provide a reproducible example of the problem</strong> he’s facing.<br>For web based projects (JavaScript, HTML and CSS), you can prepare a pen with <a href="http://codepen.io/">codepen.io</a> and ask the users to edit it to reproduce the problem.</p><p>For problems that can’t be reproduced on codepen, you may want to ask for a GitHub repository with the minimal amount of code needed to reproduce the problem.</p><p>Along with this request, you have the opportunity to ask more informations to the user, feel free to ask them all the info you may find useful to reproduce and debug the problem.</p><p>For example, this is the template I use on one of my projects:</p><pre>Thanks for your interest in contributing to Popper.js!  <br>Please, make sure to fill all the sections of the template before submitting any issue.</pre><pre>Issues without the required informations will be closed.</pre><pre>----------------</pre><pre>### CodePen demo</pre><pre>Edit this CodePen to allow the contributors to easily reproduce your problem.  <br><a href="http://codepen.io/FezVrasta/pen/wGqJEz">http://codepen.io/FezVrasta/pen/wGqJEz</a></pre><pre>### Steps to reproduce the problem</pre><pre>1.  <br>2.  <br>3.</pre><pre>### What is the expected behavior?</pre><pre>Describe what you would have expected.</pre><pre>### What went wrong?</pre><pre>Describe what went wrong.</pre><pre>### Any other comments?</pre><pre>Any additional information.</pre><p>When you create the template, you have to take in consideration <strong>how much you need feedbacks</strong> from your users.</p><h3>You need your community</h3><p>If your project is new and has just few stars, you must make the community around it larger. This is needed because without an user base and enough feedbacks, your project will never grow.<br>You need your users, they are the ones that use your project and talk about it with their friends. Without them, you could even avoid to publish your code. The community, in an open source project, is the most important thing. Without it, your project is nothing.</p><p>This means that initially, you will have to be less strict with the management of the submitted issues. You need feedbacks, you don’t receive a lot of them, just take everything comes and try to manually clean them to make them easier to organize and read.</p><p>Once your project grows and you start receiving a lot of issues, your priority will be to filter the bad feedbacks and keep only the good ones. Here you will want to strictly apply the rules and summarily close the issues that don’t respect the requirements.</p><p>I have a premade reply I insert in any issue I close that doesn’t respect them and I use to kindly thanks the user for his feedback and ask for a better quality feedback the next time.</p><blockquote>Thank you for your issue.</blockquote><blockquote>Unfortunately I can’t answer to all the reported issues without a little help from you.<br>Please, make sure to follow the <strong>issues template</strong> when you submit a new issue, in this way I will already have all the informations needed to understand the problem and help you with it.</blockquote><blockquote>I’m closing this issue for now, but feel free to open a new one making sure to follow all the instructions!</blockquote><blockquote>Thank you for your understanding.</blockquote><p>As you can see, I try to be kind, because the user spent time to report the problem he faced. But I also firmly explain that I can’t help him if he doesn’t help me first.</p><h3>Label the issues</h3><p>Labels are invaluable to make it easy and fast to read the issues list and decide where to focus.<br>They are useful bot to you, and to the potential contributors that want to help with your project.</p><p>Prepare a good set of labels that can help you to categorize the issues, you may want to have labels to identify the part of app that is afflicted by the problem, to know if it’s a bug, a feature request or an enhancement of an existing feature.</p><p>Good practice is to create a “Good first bug” label that can be used to label the issues that can be easily addressed by new contributors. This will help them to pick a good issue and get confident with your code base.</p><p>Referring again to one of my projects, I have a “Core” label I use to identify the issues related to the core of my library, a “Modifier” one I use to identify issues related to a particular plugin I ship with the library and a “Docs” one to label the issues that ask for better documentation or for problems with it.</p><p>These are some of the methods I use to keep my issues list clean and healthy, if you have more advices please let me know replying in the comments!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4fc8efa1b202" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>