<?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 Matthieu Kern on Medium]]></title>
        <description><![CDATA[Stories by Matthieu Kern on Medium]]></description>
        <link>https://medium.com/@matthieu.kern?source=rss-773e09f8f6b0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*cAOV60wgc_WYjDCM.</url>
            <title>Stories by Matthieu Kern on Medium</title>
            <link>https://medium.com/@matthieu.kern?source=rss-773e09f8f6b0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 12:56:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@matthieu.kern/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[React: Stop checking if your component is mounted]]></title>
            <link>https://medium.com/doctolib/react-stop-checking-if-your-component-is-mounted-3bb2568a4934?source=rss-773e09f8f6b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/3bb2568a4934</guid>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Matthieu Kern]]></dc:creator>
            <pubDate>Wed, 22 Sep 2021 07:53:34 GMT</pubDate>
            <atom:updated>2021-10-08T09:02:30.296Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1s3KUC6h8hwjjDa3" /></figure><p><em>This article will provide solutions to the “Can’t perform a React state update on an unmounted component” warning and why a call to setState when your component isn’t mounted is not a valid solution.</em></p><p><strong>Update 08/10/2021: </strong>Between the writing and publication of this blog post, <a href="https://github.com/facebook/react/pull/22114">the setState warning has been removed from the React codebase</a>. This change will be included in the next version of React. This article remains correct and highlights why this change has been made. Quoting <a href="https://medium.com/u/a3a8af6addc1">Dan Abramov</a> (<a href="https://github.com/facebook/react/pull/22114#issuecomment-929191048">source</a>):</p><blockquote>The post is sort of correct though. We’re removing the warning <em>because</em> people work around it with isMounted which defeats the purpose. So we might as well not warn. But the proper solution is cancellation. Or ignoring if you’re lazy about cancelling.</blockquote><p><strong>Original story: </strong>As with any other React application, we have to deal with asynchronous state updates at Doctolib, which sometimes lead to a “setState warning”. These are even more visible thanks to our thorough testing strategy, with more than 30,000 end-to-end tests that will fail on any kind of warning. Here is how we overcame the tedious process of getting rid of all our setState warnings, without checking if our components are mounted.</p><h3>A bit of context</h3><p>Like most React developers, you have probably encountered at least once in your life the “setState warning”:</p><blockquote>Warning: Can’t perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.</blockquote><p>But did you ever wonder what was actually happening and why you were getting this? If it’s there, it must be for a reason, right?</p><p>Here is a simplified timeline of what’s happening and why you get this warning:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vW849VHMcn3LHrhNF94_fQ.png" /></figure><p>Most of the time, this happens after you started a network query, unmounted the component that started this query, then handled the response to this query in a callback that also updates the state of your component. And as you call your state-dependent function, React realizes that your component is already unmounted, so ignores the update to its state and warns you that you probably have a memory leak.</p><h3>Introducing the anti-pattern</h3><p>If like me your first reaction was to search the internet for a solution to this annoying warning, you probably found an answer similar to this, in its simplest version, using <a href="https://reactjs.org/docs/hooks-effect.html#example-using-hooks-1">the cleanup mechanism of </a><a href="https://reactjs.org/docs/hooks-effect.html#example-using-hooks-1">useEffect</a>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f01f5a9376f27818ee2c388c1bc34c65/href">https://medium.com/media/f01f5a9376f27818ee2c388c1bc34c65/href</a></iframe><p>It is even possible to extract this in a hook for further use, as you may find in multiple accepted StackOverflow answers:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/170eb1755590147c0d18c24066593e75/href">https://medium.com/media/170eb1755590147c0d18c24066593e75/href</a></iframe><p><strong>Bad news: this is absolutely not a good way to deal with this warning and most resources you can find on this subject on the internet are wrong.</strong></p><p>This code is doing nothing apart from hiding the warning. React is already doing a check internally and does not update a component that has been unmounted (that’s why you have the warning). This only moves the check to suppress the warning:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dzfpy6IIyL5u9l_5aKR9uA.png" /></figure><h4>Why is this bad?</h4><p>By using isMounted or similar mechanisms, a reference is kept on the unmounted component for no reason. This is a source of memory leaks.</p><p>Also, your application will continue to execute the queries and their related callbacks. This won’t have any effect: the result of all this processing will be ignored eventually.</p><p>Finally, it’s just a very complex way of hiding a warning. If your sole goal is to ignore it, you have way more efficient ways to do it.</p><p>You can find more information about this in <a href="https://reactjs.org/blog/2015/12/16/ismounted-antipattern.html">an article from 2015 on the React technical blog</a>. Note: even though there is a suggestion on reimplementing isMounted in this article, it’s only given as a transitional phase, not as a long term solution. Also, the AbortController interface didn’t exist at that time.</p><p>And if you’re not convinced yet… In order to present the warning, React <strong>already</strong> uses a check that the component is mounted. If checking this was the way to go, they wouldn’t warn you about it.</p><p><em>Technically, React cuts off the component from the tree </em><a href="https://github.com/facebook/react/blob/17.0.2/packages/react-reconciler/src/ReactFiberCommitWork.new.js#L1175"><em>here</em></a><em> when unmounting it, then checks </em><a href="https://github.com/facebook/react/blob/17.0.2/packages/react-reconciler/src/ReactFiberWorkLoop.new.js#L656-L657"><em>here</em></a><em> in the </em><em>FiberWorkLoop if the component is still in the tree, to finally trigger the warning </em><a href="https://github.com/facebook/react/blob/17.0.2/packages/react-reconciler/src/ReactFiberWorkLoop.new.js#L536-L540"><em>here</em></a><em> if not. In this article, I’ll simplify this by saying that React “checks if the component is mounted under the hood”, which is a technical approximation.</em></p><h3>What am I supposed to do instead?</h3><p><strong>Cancel your queries!</strong> For simple use cases that are using the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API">Fetch API</a>, you should use the <a href="https://developer.mozilla.org/en-US/docs/Web/API/AbortController">AbortController API</a> to cancel your queries.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3bc030c30a91a0bae5269af3ad4b9c5a/href">https://medium.com/media/3bc030c30a91a0bae5269af3ad4b9c5a/href</a></iframe><p>I can understand if your first reaction is on the verbosity of this piece of code. But what happens here is the key to suppress this warning the right way: on line 13, when calling abort, the query <strong>stops running</strong>. Not only is its result ignored, but the then on line 4 will never be called. Instead, the code will go through the catch block, in which we can catch an AbortError and properly dispose of the code. No setState involved.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7oqTMmKi1ZUOHc7uRxTqPA.png" /></figure><p>To know more about the AbortController and the <a href="https://whatwg.org/">WHATWG</a> discussion on how to abort a fetch query, this <a href="https://developers.google.com/web/updates/2017/09/abortable-fetch">great article from the Google Developers blog</a> gives a view on the current state of the implementation and its history.</p><h4>What about non-fetch async operations?</h4><p>When I presented this in our <a href="https://medium.com/doctolib/scale-your-team-knowledge-and-cohesion-with-tech-time-d4f82cc22891">Tech Time</a> meetup, some concerns got raised as some of our codebase communicates with custom, desktop based APIs or with the <a href="https://tanker.io/case-studies/doctolib">Tanker SDK</a> we use to perform end-to-end encryption on most of our data.</p><p>For this purpose, you should implement a mechanism to cancel your async operations. It’s up to you to decide how, however, the AbortController API is very simple and adaptive, and is available mostly everywhere (<a href="https://caniuse.com/?search=abortcontroller">on most modern browsers</a> and in <a href="https://nodejs.org/api/globals.html#globals_class_abortcontroller">Node.js</a>), so this would be the recommended way to treat this problem in your custom interfaces. For instance, that’s what <a href="https://aws.amazon.com/blogs/developer/abortcontroller-in-modular-aws-sdk-for-javascript/">AWS did with their Javascript SDK</a>, <a href="https://devblogs.microsoft.com/azure-sdk/how-to-use-abort-signals-to-cancel-operations-in-the-azure-sdk-for-javascript-typescript/">as well as Azure</a>.</p><p>Some other Web APIs are also using similar implementations as the AbortController, like IndexedDB that implements an abort method on a transaction: <a href="https://developer.mozilla.org/en-US/docs/Web/API/IDBTransaction/abort">transaction.abort()</a> and the FileReader API that provides the <a href="https://developer.mozilla.org/en-US/docs/Web/API/FileReader/abort">instanceOfFileReader.abort()</a> method.</p><h3>Conclusion</h3><p>When working with the Fetch API, cancelling your queries gets easy with the AbortController. This solves 90% of the “setState warning” cases. And it gets easy to abstract the logic of the AbortController associated with the React lifecycle in a custom hook. We use this hook at Doctolib:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e61b0519202b673bc8ac94e30404c8e8/href">https://medium.com/media/e61b0519202b673bc8ac94e30404c8e8/href</a></iframe><p>So remember: <strong>if you find yourself checking that your component is mounted, it’s already too late</strong>.</p><p><em>If you want more technical news, follow our journey through our </em><a href="https://doctolib.engineering/engineering-news-ruby-rails-react/"><em>docto-tech-life newsletter</em></a><em>.</em></p><p><em>And if you want to join us in scaling a high traffic website and transforming the healthcare system, we are hiring talented developers to grow our tech and product team in France and Germany, feel free to have a look at the </em><a href="https://about.doctolib.com/jobs?department=Engineering"><em>open positions</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3bb2568a4934" width="1" height="1" alt=""><hr><p><a href="https://medium.com/doctolib/react-stop-checking-if-your-component-is-mounted-3bb2568a4934">React: Stop checking if your component is mounted</a> was originally published in <a href="https://medium.com/doctolib">Doctolib</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Engineering Manager: Being a servant leader]]></title>
            <link>https://medium.com/doctolib/engineering-manager-being-a-servant-leader-253fe08c1597?source=rss-773e09f8f6b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/253fe08c1597</guid>
            <category><![CDATA[performance-management]]></category>
            <category><![CDATA[servant-leadership]]></category>
            <category><![CDATA[engineering-management]]></category>
            <category><![CDATA[company-culture]]></category>
            <category><![CDATA[scale]]></category>
            <dc:creator><![CDATA[Matthieu Kern]]></dc:creator>
            <pubDate>Tue, 22 Jun 2021 08:53:06 GMT</pubDate>
            <atom:updated>2021-06-23T11:58:52.539Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WSYz8NH8tSfyoU8Qp9vViQ@2x.png" /></figure><p><em>This article will show you strategies you can use to build a great performing team at scale by being a servant leader, through the eyes of an Engineering Manager.</em></p><p>Doctolib has three missions: improve the daily life of healthcare personnel, improve patient access to healthcare and patient health and build a team of entrepreneurs with humanistic values. Here is a summary of my experiences as an engineering manager (EM) and how it contributes to these missions.</p><p>When I joined Doctolib four years ago, there was only one engineering manager. The concept of feature teams was fairly new to us, as we were evolving from a more traditional front/back organization. We were only 10 developers and the role of an EM has changed a lot since then. I myself joined as a full stack developer and grew into an EM position after one year. This job transition is <a href="https://medium.com/doctolib/becoming-an-engineering-manager-a612de1c6aaf">not uncommon at Doctolib</a>.</p><h3>CEO of your mini startup</h3><p>The main mission of an EM is to take good care of their feature team. At Doctolib, we believe that your team is your first priority: before working on strategic topics or transversal projects, the most important thing is the wellbeing and efficiency of the team.</p><p>At Doctolib, an important fact is that the EMs are accountable for the delivery of their teams, both quality-wise and productivity-wise. But we are expected to help as coaches, not as superheroes. One thing that I came to realize and discover is how important it is to actually build and grow my team. Bear with me to discover what’s exciting about the role.</p><h4>Building your team</h4><p>At Doctolib, we grow so fast that creating new teams happens day in day out. A new team can start from the split of a large team or totally from scratch with a brand new mission. In any case, there will be some seats to recruit for. We have a Talent team helping us with that, doing most of the heavy lifting, but your role here is to be the hiring manager: take decisions on whether to recruit or not someone… And give hints to the Talent team in finding the best candidates for you!</p><p>You’re in charge of defining what you’re looking for. It’s very hard to detect and close the right talents, especially when you’re looking for some specific skills. That’s the most challenging, but also the most interesting part: as you compose your team, you’re accountable for all the decisions you make. You will have the opportunity to refine every open position: define expectations, what level of seniority you’re looking for, etc. Also, while all of our developers are fullstack, we try to select talents bringing complementarity and diversity to the team. But at the end of the day, the one question you need to answer is: “will this candidate be a good fit for the team?”.</p><p>My advice is to focus less on the candidate’s track record and more on what happens during the interview. In my first attempts at interviewing, I was very focused on the previous experiences of the candidates. I quickly realized that this only works to some extent, as many candidates are just following the rules and processes in place. My go-to questions are now roleplay situations: “You’re joining my team, I have a very good performer with high potential, and I’m asking you to mentor them. What do you do?”. I find it more insightful, as you’ll get to see how they use their previous experience and knowledge to solve a problem. This sounds simple, but completely changed my perspective on how to assess candidates.</p><p>And even if your first priority will be on your team composition, this is a collective success. Ultimately, what we care about is building the best company, not just the best team. As such, we’re always recruiting even if our team does not have an open role.</p><h4>Developing your team</h4><p>Although recruitment is an important part of the job, most of your energy should go into developing your team. You’re in charge of building personalized development plans for all individual contributors of your team, based on their expectations and the opportunities the company can offer.</p><p>That’s what I love the most about my job but also what challenges me the most: I have the chance to work with skilled people who deliver super qualitative work. Even if they need my support sometimes, they are mostly autonomous and would do just fine if I disappeared tomorrow. That’s where the difficulty comes: I constantly need to find ways to challenge them, push them to do even better, developing their potential to the maximum.</p><p>Recently, I had a quarterly review with one of my teammates, a super good individual contributor who joined the company a few months ago with huge potential. I want to see him shine more and have a bigger impact on the wider company, outside of the team. The encounter quickly shifted from congratulating him for his successes to how to get him out of his comfort zone, which challenges would interest him to pick up. I think this discussion summed up quite well the way we do things at Doctolib: we believe that the best way to grow people willing to develop themselves, especially our top performers, is to push them to stretch themselves and be bold, rather than staying in their comfort zone. Supporting our employees, especially our top performers, is a constant focus.</p><p>Through encounters like this, I have discovered a number of learnings on how to develop engineers’ careers, but these two are the most important in my opinion:</p><p><strong>You have to adapt to your team</strong></p><p>I realized with time how different are my individual contributors’ personalities and aspirations, and the need to adjust my management style to each individual. Diversity is a strength: as engineering managers, we are looking to compose a team, with everyone’s strengths and areas of progress to always have the best set of competencies for every problem. We don’t try to have everyone fitting in one mold at Doctolib, we rather develop customized career paths for each individual.</p><p><strong>You need to focus on building up the team spirit</strong></p><p>I didn’t quite consider at the beginning of my management career how team spirit is important and is different from what I thought it was. A team is not only a bunch of people working together: I’m spending a lot of time and energy in making the team really act as a team: organizing regular team building activities (we have a cooking challenge in a couple of weeks!), but also simple things like keeping the whole team focused on only one subject at a time.</p><h4>But… How do we get good at it?</h4><p>There is a full management framework you can use, with rituals and tools that you can implement. Or choose not to. The most common ones are the <a href="https://medium.com/doctolib/how-to-ruin-a-1-1-56437b2409e2">weekly one-on-ones</a> you will meet every one of your individual contributors for 30min individually every week. This is used to build your relationship with them. I’m personally dividing my one-on-ones into 3 parts of 10min each: team member update, manager update and follow up on career development. While ramping-up as a manager, I listened to <a href="https://www.manager-tools.com/2005/07/the-single-most-effective-management-tool-part-1">this great series of podcasts by Manager Tools</a> on how to run these management duties.</p><p>We collectively try to build the best group of managers, as we know that will be the best way to propagate our culture. To do so, we built internal training programs to accompany our managers in their journey:</p><ul><li>The general manager academy: training sessions held by already established managers, which presents the basics of management at Doctolib</li><li>The EM academy: much more focused on the EM role, with a lot of resources (ex: how to set objectives, how to manage poor performers…)</li><li>The M-Mentor program: regular group discussion between new and experienced managers on their day to day challenges and learnings</li><li>The management clinic: monthly sessions to discuss around a chosen topic, like managing individual contributors’ long term goals</li></ul><h3>In charge of engineering</h3><p>What distinguishes engineering managers from people leads at Doctolib is that we are as much focused on the technical side of things as we are on the people’s side. I, as most of my colleagues, am far from being the best techie in my team. My role is to keep a global perspective of what we are doing technically, to maintain coherence and alignment with the global tech strategy.</p><p>Even if you’re not expected to be the best developer as an EM, you’re still expected to be hands on in some matters. This goes from challenging architecture, reviewing code and even opening a pull request sometimes!</p><h4>Project management</h4><p>We are working closely with the Product Manager (PM) of our teams. The role involves giving high level estimations of the effort needed by a project, participating in tech/product workshops, proposing technical shortcuts for our future projects, challenging the solutions so it makes sense technically…</p><p>Once the roadmap is defined, we’re in charge of the delivery. It’s one of the main missions of the engineering manager: make sure we’re on time and communicate any delay.</p><h4>Technical advocate</h4><p>One of the main aspects of the job is to be the voice of tech. In our close relationship with our PMs, we need to be the two faces of a single coin: the PM carries the product vision, with customer needs, dependencies with other teams etc, while the EM is responsible for defending the tech decisions: do we need to add some budget to refactor some piece of code? Will the project generate performance issues? etc. Even if all EMs are expected to have a good product sense to some extent, they are the only guardians of a good, reliable tech.</p><h3>Actor of change management</h3><p>The cool thing is that we’re building the best team, but the true team is Doctolib. Similar to how we participate in hiring, we are also encouraged to get involved in various initiatives, and proactively push for change.</p><h4>Tech initiatives</h4><p>As we are growing so quickly, we face many challenges. To counter these, we started a lot of transverse projects, called “Tech Initiatives”. We grouped them under those categories:</p><ul><li>Tech quality: Have the best development &amp; rollout practices, at scale. This contains tech debt management, security by design…</li><li>Product Quality: Have the most reliable product, react well when not. Contains bugs management, performances…</li><li>Dev Efficiency: Make it easy to find information, ramp up, and work with stakeholders. This is about knowledge management, tech onboarding…</li><li>HR/Dev Community: Invest in the growth of our organization and its members. This includes hiring, career growth, diversity and inclusion…</li></ul><p>Engineering managers are in the driver seat for these initiatives. Initiatives are open to anyone in engineering, on a voluntary basis, but EMs are typically more involved and expected to make things happen. All EMs are not working on everything: every EM will usually be part of 2–3 initiatives at the time at max. I’m personally working on EM academy, crisis management and hiring initiatives at the moment.</p><h4>Small scale experiment</h4><p>Tech initiatives have their importance, but sometimes you don’t need the big guns. One good thing about Doctolib is that we have the freedom to experiment at a small scale.</p><p>I have a great working experiment running in my team at the moment: innovation Fridays. One Friday a month is dedicated to personal development and experimentation. At first, it was really innovation oriented: working on proof of concept, trying to introduce new technologies to solve problems. But, today, in my current team, this took another purpose: learning. I had a lot of complaints within the team that we did not have enough learning time, as such I re-introduced this ritual for us but with a different pitch: this is a time for you to learn and discover things. You watch a conference, go through a tutorial, discover a new technology… And since it’s working swimmingly, I have just shared it with my fellow EMs a couple of weeks ago.</p><h3>Conclusion</h3><p>To sum up, the engineering manager is a vital organ of the organization. What I love about Doctolib is that as a manager, we put a lot of diligence in building that best team &amp; culture. Overall, we are the <a href="https://en.wikipedia.org/wiki/Servant_leadership">servant leaders</a> of the tech team: always there to serve, both our internal employees and our customers.</p><p><em>If you want more technical news, follow our journey through our </em><a href="https://doctolib.engineering/engineering-news-ruby-rails-react/"><em>docto-tech-life newsletter</em></a><em>.</em></p><p><em>And if you want to join us in scaling a high traffic website and transforming the healthcare system, we are hiring talented developers to grow our tech and product team in France and Germany, feel free to have a look at the </em><a href="https://about.doctolib.com/jobs?department=Engineering"><em>open positions</em></a><em>.</em></p><p><strong>Thanks</strong> to Alexandre Ignjatovic, Charlotte Feather and Thibault Martin for reading drafts of this and Gaëlle Malenfant for the cover picture.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=253fe08c1597" width="1" height="1" alt=""><hr><p><a href="https://medium.com/doctolib/engineering-manager-being-a-servant-leader-253fe08c1597">Engineering Manager: Being a servant leader</a> was originally published in <a href="https://medium.com/doctolib">Doctolib</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Treating Technical Debt]]></title>
            <link>https://medium.com/doctolib/treating-technical-debt-62630ee64ef7?source=rss-773e09f8f6b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/62630ee64ef7</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[refactoring]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[rxjs]]></category>
            <category><![CDATA[es6]]></category>
            <dc:creator><![CDATA[Matthieu Kern]]></dc:creator>
            <pubDate>Mon, 04 Jun 2018 07:31:33 GMT</pubDate>
            <atom:updated>2019-10-21T20:37:39.365Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WNKtu2kT2DmBITmNVXwjtQ.png" /><figcaption>illustration by <a href="http://www.baileymcginn.com/">Bailey McGinn</a></figcaption></figure><h4>How We Handle Forms at Doctolib Then and Now</h4><p>As your codebase grows larger and you begin to accumulate legacy code, it naturally becomes more and more difficult to work with. This concept is called <em>technical debt</em>, and the unfortunate outcome is that it requires extra work from the developer to implement features because the code is tough to understand and difficult to expand.</p><p><strong>Racking up technical debt is unavoidable, yet treatable. </strong>The following article explains how we unified the process by which we build forms in an attempt to reduce our technical debt at Doctolib.</p><h3>Looking back on our legacy</h3><p>Over the years, we have gone through multiple ways of building forms either by using external libraries or developing internal tools to do so. For example, we had <a href="https://github.com/doctolib/react-form">an abstraction on top of formsy-react</a> which we eventually dropped in favour of a custom implementation using RxJS.</p><h4>The observable hell</h4><p>Most of our forms were making heavy use of RxJS observables (one for each field) and being injected into React’s context using <a href="https://neoziro.github.io/recompact/">Recompact</a>. More fields on a form means more observables, which tend to make the form declaration cumbersome and difficult to maintain. For example, one of our most complex forms is one that manages an appointment; it became increasingly more difficult to maintain this form with <strong>more than 30 observables</strong> provided to manage fields:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6fd5d6102b553e8941d55da9aedb2101/href">https://medium.com/media/6fd5d6102b553e8941d55da9aedb2101/href</a></iframe><p>There are multiple issues with the above code:</p><ul><li><strong>It became difficult to browse</strong> because the observables provided through the context reduce the links between components</li><li><strong>It was duplicated a lot</strong>, especially between the web and mobile parts, making it sometimes difficult to debug the code</li><li><strong>It was challenging to read</strong>, mainly because we over-engineered it by over-composing it using Recompact</li></ul><h4>State of the art: Forms using RxJS</h4><p>At this point, we developed an API in an attempt to reduce this observable hell. The idea was to contain the use of RxJS in a few helper functions. The base API was composed by a set of two Recompact <a href="https://reactjs.org/docs/higher-order-components.html">HOCs</a>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/708d12417c0882eb6af4cd33bbe94c2d/href">https://medium.com/media/708d12417c0882eb6af4cd33bbe94c2d/href</a></iframe><p>It was pretty straightforward in the beginning; we needed only to call connectField on our field and use the value and onChange props:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c27370b10be65536802350f53514f773/href">https://medium.com/media/c27370b10be65536802350f53514f773/href</a></iframe><p>This implementation did provide some clarity, however, it still had a few issues including: a dependency between the fields, problematic errors and validation management, and always having to give the value and onChange props to our display components which should have managed it automatically. All of these issues ended up resulting in the production of boilerplate code that we could have avoided.</p><p><strong>Because of those trade-offs, we decided to move to a more maintainable and easy to read implementation.</strong></p><h3>Introducing react-form</h3><p>We could have chosen to improve our own API, but instead of creating an inhouse set of helpers, we decided to switch to <a href="https://react-form.js.org/#/">react-form</a> in order to unify our codebase.</p><p>React-form is a cool tool-set used to build forms with React:</p><ul><li>It provides some basic input components (like Text, Select, Checkbox…)</li><li>It gives a formApi which is used to manage the state of our form</li><li>Its fieldApi lets us create custom inhouse inputs</li><li>It is bundled with a validation API for errors state management</li></ul><h4>Building custom components on top of react-form</h4><p>However, we were not completely satisfied with react-form’s basic APIs. Being heavy users of the great Rails <a href="https://github.com/plataformatec/simple_form">Simple Form</a> library and admirers of its simplicity, we built our components on top of the react-form API based on its principles in order to obtain the best developer experience possible.</p><p>To do so, we first wrapped the Form component into a custom one in order to avoid boilerplate code. As it turns out, we seldom use the formApi, except when passing submitForm to our &lt;form&gt; tag, so we wrapped it up:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c7c91726691ff72793aa3e4aeb782ff/href">https://medium.com/media/8c7c91726691ff72793aa3e4aeb782ff/href</a></iframe><p>Next, we had to migrate all our custom inputs in order to use fieldApi. Fortunately for us, the third version of react-form introduced a wrapper component <a href="https://react-form.js.org/#/custom-input">Field</a> which does almost all of the work for us. It gives us the API we need to manage the state of input regarding the form. Here is a simple example of the code of our Selector container:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c2113566c2cebff844bc7c055fca3f4/href">https://medium.com/media/3c2113566c2cebff844bc7c055fca3f4/href</a></iframe><p><strong>We had some issues regarding the </strong><strong>fieldApi.value that was not up to date in some cases.</strong> If your component is not re-rendered when the value mutates (e.g.: if you use <a href="https://github.com/nosir/cleave.js/">Cleave.js</a>), the fieldApi won’t be either. This means none of its data (value, error, warning, success, touched and fieldName) gets updated. Our current workaround is to retrieve the formApi from the context and use its getValue method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/38586d6dab9f6360afdb9585c9ad176f/href">https://medium.com/media/38586d6dab9f6360afdb9585c9ad176f/href</a></iframe><p>We also created an Input component, which accepts a type prop. However, if type is not provided, it will try to match the field name and props to generate its type in the same manner as Simple Form. We could write a whole separate article about this magical component:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/87fecac0c900fa1511d4c2c94d52fe5b/href">https://medium.com/media/87fecac0c900fa1511d4c2c94d52fe5b/href</a></iframe><p>The resulting API is something pretty simple to use and easy to read:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aa18cd84b76186def395702b41c6a1c9/href">https://medium.com/media/aa18cd84b76186def395702b41c6a1c9/href</a></iframe><h3>Killing the legacy: Migrating all of the code</h3><p>In order to handle this massive refactoring, we created a cross-teams task-force with one single goal: <strong>kill legacy code</strong>. As the tech team grows (we are currently at more than 25 developers and we plan to be 40 by the end of the year), it is very important to work on simplifying our codebase. No one is dedicated full time to refactoring forms, but we manage to dedicate roughly half a day each week to cleaning the codebase.</p><h4>Technical tasks</h4><p>“Tech tasks” at Doctolib are tasks with no direct product value (they’re not a new feature), but instead are those which have technical value (e.g.: improving developers efficiency, enhancing the platform performances, etc.). These large projects are prioritized in a tech roadmap which is maintained in parallel with the classic product roadmap. This is not only a refactoring time, it is also time allocated to experiment with new technologies, to keep ourselves up to date and so on.</p><p>Four of us worked on this particular task. We plotted a six month long roadmap for the transition to the new forms standard which started late December and the plan is to have the last form migrated by June.</p><h4>How we kept the product evolving in parallel</h4><p>The idea was not to jam the development of new features while refactoring the forms. To avoid doing so, we ensured that each form we migrated had no changes scheduled within the next few weeks. It is very important when you start such a refactoring to know the next product focuses and to work with the parts in which no evolution is planned. Still, as we went we did have to make some minor changes and bug fixes from the main trunk to our feature branch.</p><p>We also decided that this was a good time to update our forms’ graphic design, and to ensure its unification across the rest of the app:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*poKIUC3Pctuu3Q7U." /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xpPEbqtJGPWwftIO." /><figcaption>The form then (on the left) and now (on the right)</figcaption></figure><h4>How we kept the same great quality through the refactor</h4><p>We were able to perform a quick and safe refactor with the confidence that the forms we were shipping worked just as well thanks to two things : a whole lot of unit tests, and even more integration tests.</p><p>We love tests at Doctolib: our test suite includes <strong>more than 6000 unit tests and 1000 end to end tests </strong>which run on Heroku CI for each commit we push to Github. It took a while, but we finally got a green build on our refactor.</p><p>For some of our forms which do not change graphically, we also have visual regression tests that helped us a lot (using a custom version of <a href="https://github.com/argos-ci/argos">Argos CI</a>).</p><h4>Transmitting knowledge to the other developers</h4><p>Since making developers’ lives easier was one of our main goals, <strong>sharing the knowledge to the rest of the team is a crucial part of the process</strong>.</p><p>We have a few channels to do so:</p><ul><li>By providing clean implementation examples: we have some forms which are tagged as “state of the art” which other developers can read and tinker with</li><li>During “tech time” meetings: a weekly gathering of our technical team, where anyone can share something great they did that could be useful to others.</li><li>Being a cross-teams project, there is a point person on each team that can help his team mates using the new API</li><li>On an internal wiki</li><li>Hopefully through this article :)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*lcLjeFp3z5Jvx4J9aFyDJw.png" /><figcaption><a href="http://bit.ly/doctotechlife">Get our news here</a></figcaption></figure><h3>Conclusion</h3><p><strong>Gathering technical debt is unavoidable. </strong>When your business is growing fast, you don’t always have the time to keep your codebase perfectly clean and it’s probably not a good idea to spend too much time cleaning your code anyway.</p><p>You have to <strong>find the balance between over-engineering and mess</strong> to continue to expand your application and your business. Good development practices can help avoid technical debt, in particular, code reviews, but <strong>never forget to take a step back and figure out if you are still heading in the right direction</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62630ee64ef7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/doctolib/treating-technical-debt-62630ee64ef7">Treating Technical Debt</a> was originally published in <a href="https://medium.com/doctolib">Doctolib</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>