WhoBuilt

React developer? How are your production skills?

Sep 14, 2018· 25 min· 103 views·Watch on YouTube

Speaker

Independent consultant Michael Haberman explains how to prepare React web apps for production at a Callstack event.

Why production causes problems

Haberman says production issues often arise after code reaches users, even when developers know their tools and follow good practices. Browser and operating system differences, along with user behavior that QA did not test, can expose problems.

Keep deployed bundles fresh and small

Browsers can serve cached files after a release, leaving users on an older app. Haberman demonstrates adding a changing hash to bundle filenames and generating the matching filename for the HTML page. He also recommends building in production mode, optimizing with Webpack, and using gzip to reduce file size.

Capture and reproduce runtime errors

A simple example works in Chrome but fails in Safari because Safari does not support `event.path`. Haberman recommends collecting browser errors with a service such as Sentry or Rollbar, and using source maps to make minified stack traces easier to read. Logging application state changes can help engineers reproduce bugs from users’ actions.

Deploy the same tested dependencies

Haberman describes bugs that appear in production despite passing QA, including problems caused by installing different npm package versions during deployment. He recommends promoting the same build artifact or Docker image from QA to production. If packages must be reinstalled, specify exact versions rather than loose ranges.

Takeaways

  • Use content-hashed bundle filenames so browsers fetch new code after a release.
  • Build and optimize React apps in production mode, and consider gzip for smaller transfers.
  • Collect runtime error reports with browser and operating system details, and enable source maps for debugging.
  • Log application state changes to make user-reported issues easier to reproduce.
  • Promote the same tested artifact to production, or pin exact dependency versions.

Mentioned in this talk

Search inside this talk

What was claimed 6

  • feature
    webpack: Can generate hashed bundle filenames to support cache busting
    “This hash changes every time we run Webpack”
    YouTube
    Unverified1 source· Talk
  • feature
    webpack: Production optimization reduces the generated application file size
    “add minus P, which means optimizing”
    YouTube
    Unverified1 source· Talk
  • feature
    Sentry MCP: Provides error reports with user, browser, operating system, page, and timing details
    “you can get a lot of data: which user, which browser, which operating system and version, which page, and when”
    YouTube
    Unverified1 source· Talk
  • feature
    source maps: Help interpret stack traces from minified code
    “So how do you solve reading minified code? Source maps.”
    YouTube
    Unverified1 source· Talk
  • feature
    LogRocket: Can be used to log store changes to help reproduce application bugs
    “LogRocket is just one I’ve had experience with”
    YouTube
    Unverified1 source· Talk
  • feature
    Docker: Allows a built image to be moved from one cluster to another for deployment
    “move your image from one cluster to another, and it just works”
    YouTube
    Unverified1 source· Talk

Related talks