Enabling React Development Mode in the WordPress Block Editor (Gutenberg)

The React development mode provides useful warnings and errors. It’s therefore useful when developing custom blocks.

However WordPress loads the minified production build of React by default, as it it offers better performance. In this article we’ll look at how to enable React’s development mode to help you debug issues with your custom blocks.

What is the React Development Mode?

React development mode is a feature provided by the React JavaScript library that aids developers during the development and debugging phases of building web applications. It’s designed to provide useful warnings, debugging information, and performance optimization suggestions, which are instrumental in the development process.

Here are a few key aspects of React development mode:

  1. Warning Messages: In development mode, React displays a variety of warning messages in the browser’s console. These warnings are meant to catch common mistakes and issues in your code, such as prop type mismatches or incorrect usage of React components.
  2. Detailed Error Information: If an error occurs within your React application, the development mode provides detailed error information, including the component stack trace. This information is invaluable for pinpointing the source of errors and debugging effectively.
  3. Performance Warnings: React development mode also issues performance warnings when it detects potential bottlenecks in your application. These warnings can help you identify areas where your application might benefit from optimizations.
  4. Verbose Logging: Development mode may log additional information about component updates, rendering, and state changes. This can be useful in diagnosing issues related to component behavior.

It’s important to note that React development mode is designed to be used during development and debugging, and it has a performance cost. When you’re ready to deploy your application to a production environment, you should build it in production mode, which omits the development-specific warnings and logging to optimize performance.

Enabling the React development mode in WordPress

To use the React development mode in WordPress, you need to set the SCRIPT_DEBUG constant in your wp-config.php file to true.

define( 'SCRIPT_DEBUG', true );

As a result, WordPress will load the development version of React, and all other third party script dependencies.

Verifying that development mode is enabled

To verify which version of React is running, you can use the React Developer Tools for Chrome. It adds an icon to the browser that changes depending on which React version is running.

If you are on a website using the React production build, the icon will have dark background:

React DevTools icon on a website with production version of React.

However of the development build of React is loaded, the icon will have an orange background:

React DevTools icon on a website with production version of React

Seeing error messages

To see the error messages, open the browser’s JavaScript console.

You are now ready to start developing your own WordPress blocks.

If you’re looking to learn custom block development, check out the guide to learning custom block development.

Level Up Your WordPress Development Skills With One Email Per Week

Every Sunday, I send out tips, strategies, and case studies designed to help agencies and freelancers succeed with modern WordPress.

My goal is to go off the beaten path, and focus on sharing lessons learned from what I know best: building websites for clients.

100% free and 100% useful.

Feel free to check out the latest editions.