Reducing Technical Debt in your React App

by Josh Owens

March 22nd, 2023

In the fast-paced world of web development, delivering features quickly and efficiently can take precedence over code quality. As a result, developers sometimes cut corners or postpone code refactoring, inadvertently creating what is known as technical debt. Technical debt refers to the hidden costs of maintaining, enhancing, or fixing less-than-optimal code accumulating over time. You can think of technical debt in terms of construction when you remove the drywall to renovate a room and find old/unsafe wiring that needs replacing. While some degree of technical debt is inevitable in most projects, preventing a significant impact on delivery speed, maintainability, and overall software quality becomes crucial.

It is essential to recognize the challenges posed by technical debt and implement strategies to mitigate and manage a scalable and maintainable React application. Ignoring technical debt can lead to a slower development cycle, increased difficulty implementing new features, and higher chances of introducing bugs. It becomes particularly challenging in React applications due to their component-based architecture, resulting in increased complexity, duplicated code, and challenges related to state management.

Identify and Prioritize Technical Debt in your React App

The first significant step in paying down technical debt is implementing tooling into the code development process to help identify and remove the debt.

Code Quality tooling

The easiest step for a Javascript/Typescript project is to add something like ESLint or Prettier to your app. It can be set up to run from a command line, add a git hook to force it to run as part of the commit process, and easily add a configuration to run it as part of a pipeline via Github or Gitlab.

The other noteworthy part about ESLint and Prettier is their tight integrations with IDEs. The rules are easily configured to help you find and remove technical debt, like finding and disallowing console.log in your code.

Another great tool is CodeHawk (or other static code analysis options like Code Climate) to review your code and suggest spots needing help. Static Code analysis examines code for complexity using various measurements and can identify areas ripe for refactoring code to reduce things like Cyclomatic Complexity.

Code Reviews

While automating code quality tools can be super helpful in your quest to reduce technical debt in your React application, nothing beats a code review by a human. Often that can be more than one way to attack the technical debt, and when another person reviews the code, they may see potential issues you missed while working on the code.

Most teams we have worked on have a 1 or 2 person approval process before someone can hit the merge button. You can also start to get fancy with Github and Gitlab using code owner files and auto-tag reviewers into a pull request and code review process automatically based on the location of the code in the app. For example, you break your teams into Search, Product Display, and Checkout. If someone in the Product Display team needs to change the checkout code, they can open a PR, and a code owners file would detect it was changed in the checkout folder and tag the checkout team to review/approve the code change.

Code Fixers: A Comprehensive Solution for Technical Debt

In addition to the tools and techniques mentioned above, you might consider enlisting the help of a dedicated service like Code Fixers to tackle your technical debt more effectively. Code Fixers offers a white-glove service for your code, providing development subscriptions to debug, test, and keep your code secure. The team of experts can assist with code reviews and bug cleanup and help ensure your React app remains maintainable and scalable over time. By leveraging the expertise of Code Fixers, you can focus on your core feature development tasks while they handle the challenges of managing technical debt in your React application.

Tracking and categorizing technical debt

We’ve often joined teams with a mission to pay down technical debt, a concerted effort by many developers to focus on. Organizing is where tools like JIRA and Trello come in handy. You can have conversations as a team and identify things you want to fix in the code, then create something like a JIRA epic and add tickets for code changes related to the tech debt you wish to remove.

Some of the more prominent focuses could be on code quality, performance issues, code architecture, and test coverage. For example, we were working on a project, and the goal was to prepare for changes coming in React 16. Two devs reviewed the React changelog and docs and figured out what we needed to change. They created a JIRA epic, looked through the code to find the trouble spots, and wrote tickets for each location. Those tickets were distributed to each team, picked up, and worked on for over a month. Once everything was complete, the core two team members started working on the upgrade.

Prioritizing debt based on impact and effort

When you decide that tackling technical debt becomes a focus, it is advisable to figure out how the technical debt tickets will be prioritized. My suggestion is to create a matrix of things to consider;

  • What area of the code is impacted?
  • Does leaving the debt slow down development speed?
  • What are the potential risks of fixing the debt?
  • How much expertise will the fix take?
  • Does it affect the React application’s performance, maintainability, testability, or security?

Once you have your matrix, you can start sorting your technical debt into groups of severity (low, medium, high) and types of debt (performance, security, etc.). Once you sort things out, you can target the most critical and high-value technical debt as an easy first step.

Dependency management

Speaking of upgrading versions, let’s discuss dependency management and how that can help with technical debt. When newer libraries and plugins are released, they usually contain security fixes and performance improvements. Getting regular updates on these types of dependencies can be beneficial, and you can set up a standard process like this:

  1. Use package managers like npm and use package-lock.json. You can use the npm outdated command will show things that need updating
  2. If you have unit and functional tests, you can upgrade the identified packages and then run tests
  3. Open a PR and then test the app either locally or in a test in a preview environment to make sure the app still works

You also have other tools available to you. If you use something like Github, you can integrate Dependabot to open its pull requests into your app, and then you test the branch out.

Closing Thoughts on Technical Debt

Addressing technical debt in your React application is essential for maintaining a scalable, high-quality, and maintainable codebase. To effectively combat technical debt, it’s crucial to identify and prioritize the issues, employ code quality tools, conduct regular code reviews, track and categorize the debt, and manage dependencies proactively. By following the strategies and tools discussed in this blog post, you can keep technical debt under control, minimize its impact on your development cycle, and ensure your React app remains performant, secure, and maintainable over time. Remember, staying vigilant and taking a proactive approach to managing technical debt is the key to long-term success in the fast-paced world of web development.

Like this post?

Try another post: 5 Essential VSCode Extensions for React Developers

Go Back

Kick your software into gear