so, you want to build a web app

🐛 debugging

or, the “rinse, lather, (hopefully don’t) repeat” part.

tl;dr


Chrome DevTools

the tools built into your browser are incredibly powerful these days. there’s a lot to say on how to use these tools. you should start by just taking any random website you like and mess around with it using the tools. once you’ve played with it a little bit, go read the reference docs. make sure you’ve enabled sourcemaps with your bundling tool. create-next-app’s bundler config should have these on by default.

i won’t go over every feature in this guide, but i’d like to point out some highlights and tricks/tips that i’ve found commonly ignored by engineers:

your bundler, by the way, will create source maps so that your files that are bundled for your app can be mapped backed to the original code in development mode for easier debugging within Chrome’s DevTools.

on the topic of your bundler, another mention here in your workflow is that webpack allows for hot module replacement (HMR). this allows for a much faster iteration cycle, especially when debugging a particular section of code.


React DevTools

a must-have tool to debug React components, changing their state and props on demand.

some highlights and tricks/tips for React DevTools:


node

to be able to debug node.js, you must launch it with the --inspect flag. from there, you can use your favorite editor/IDE and attach the debugger to the process. you usually have to specify the port (defaults to 9229) and then you’re off to the races! it should work more or less like Chrome’s DevTools debugger.

other configuration options:

if you visit chrome://inspect in your browser, this will allow you to connect your editor to the V8 debugger protocol.


tracking errors

exception handling

at the very least, you need to gather exceptions from your clients and send them up to your server so you know what errors are happening to your users out in the wild. if you’re lucky you will have passionate users that will mercifully report to you bugs they are experiencing. (thank your lucky stars!) but a lot of bugs will go unnoticed and unreported manually by users. and, they might only happen in certain special cases or in certain browsers/countries/days of the week/what have you.

some other notes:

logging

related to the above is logging on your backend. you should be logging not only exceptions but everything you can on your backend. this will prove to be vital when you inevitably come across a problem and, like a detective, try to piece together the series of events that led to a failure.

a paid option that is useful in production is Sentry. i wish Sentry was better: it feels heavy-handed, the dashboard UI can be clunky, and there’s a lot of background noise from random browser bugs that are false positives…but there’s nothing else contending with it. i’m exploring the tool Highlight these days as an alternative.


post-mortems

one thing to mention here is documenting via a process called a “post-mortem” especially if they happen in production taking your website down. by writing down what went wrong and how you solved it, you start to build the to help notice patterns of failure, learn from your mistakes and cohesively learn how to solve it going forward.


resources