Skip to main content

Tutorial NextJS - Day 2

Hari 2 – Navigasi, Layout, & Dynamic Routing Setelah berhasil melakukan instalasi dan membuat halaman pertama di Hari 1 , pada Hari 2 ini kita akan membuat website menjadi lebih hidup. Kita akan belajar cara membuat menu navigasi agar bisa pindah-pindah halaman, membuat tampilan menu yang konsisten (Layout), dan membuat halaman artikel yang pintar (Dynamic Routing). Tutorial ini tetap menggunakan Windows + VS Code dan melanjutan project nextjs-basic dari hari sebelumnya. 1. Navigasi Antar Halaman ( <Link> ) Di HTML biasa, kita menggunakan tag <a> untuk berpindah halaman. Namun, di Next.js kita menggunakan komponen khusus bernama <Link> . Kenapa harus pakai <Link> ? Jika pakai <a> , layar akan berkedip (loading ulang) setiap pindah halaman. Dengan <Link> , perpindahan halaman terjadi instan tanpa refresh. 1.1 Edit Halaman Home Kita akan menambahkan tombol untuk pergi ke halaman About. Buka file src/app/page.tsx , lalu ganti isinya dengan kod...

React Build vs Development Mode: What’s the Difference?


Introduction

Many React developers are surprised when their app works perfectly during development — but behaves differently after deployment. Features break, routing fails, environment variables disappear, or performance changes dramatically.

Most of these issues come from not understanding the difference between React’s development mode and production (build) mode.

In this article, we’ll explain:

  • What development mode really does

  • What changes in production builds

  • Why bugs appear only after deployment

  • How to avoid common build-related mistakes


What Is Development Mode in React?

Development mode is what you use when running commands like:

npm start npm run dev

In this mode, React prioritizes developer experience, not performance.

Key Characteristics of Development Mode

  • Detailed error messages

  • Helpful warnings

  • Hot reloading (instant updates)

  • Slower performance (on purpose)

  • Extra checks for unsafe patterns

Development mode helps you find bugs early, but it is not optimized for real users.


What Is Production (Build) Mode?

Production mode is created using:

npm run build

This generates a static build optimized for real users.

Key Characteristics of Production Mode

  • Smaller file sizes

  • Faster load times

  • Minified JavaScript

  • No dev warnings

  • Optimized rendering

Production builds focus on performance and stability, not debugging.


The Core Difference (One Sentence)

Development mode helps developers, production mode serves users.


Why Apps Behave Differently After Build

Here’s where many developers get caught off guard.


1. Error Messages Disappear in Production

In development, React shows detailed error messages.

In production:

  • Errors are minified

  • Stack traces are shorter

  • Messages are less descriptive

Why This Matters

You must:

  • Fix warnings in development

  • Never ignore console errors

  • Test thoroughly before building


2. React Strict Mode Runs Effects Twice (Development Only)

React Strict Mode intentionally runs certain lifecycle logic twice in development.

This helps detect:

  • Unsafe side effects

  • Incorrect cleanup logic

In production:

  • Effects run only once

Common Confusion

Developers think:

“My app is broken, effects are firing twice!”

But this is expected behavior in development.


3. Environment Variables Behave Differently

Environment variables are a major source of production bugs.

Common Issues

  • Variable works locally, but is undefined in production

  • Wrong variable prefix

  • Forgot to rebuild after changing .env

Examples

  • Vite requires VITE_

  • Create React App requires REACT_APP_

Important Rule

Environment variables are baked into the build.

Changing .env requires rebuilding the app.


4. Build Mode Is Much Faster (and Less Forgiving)

Production builds:

  • Remove development helpers

  • Optimize rendering

  • Assume your code is correct

This means:

  • Hidden bugs can surface

  • Race conditions may appear

  • Timing-related issues become noticeable


5. Source Code Is Minified

Production JavaScript is:

  • Compressed

  • Renamed

  • Harder to read

This improves performance but makes debugging harder.

Best Practice

  • Debug issues in development

  • Use source maps if needed

  • Log meaningful errors yourself


6. Asset Paths Change in Production

In development:

  • Assets are served dynamically

In production:

  • Paths must be correct

  • Base URLs must be configured properly

Incorrect paths often cause:

  • Blank pages

  • Missing CSS

  • Broken images

This is especially common when deploying to subfolders.


7. Hot Reloading Is Gone

Development mode updates instantly.

Production mode:

  • Requires a rebuild

  • Requires re-uploading files

Many developers forget this and wonder why changes don’t appear.


Why Bugs Appear Only After Deployment

Most production-only bugs are caused by:

  • Missing environment variables

  • Incorrect build paths

  • Server misconfiguration

  • Routing issues

  • Cached old builds

React is not breaking — the environment is different.


How to Test Production Behavior Locally

Before deploying, always test the production build locally.

Example

npm run build npm run preview

This simulates how the app behaves in production.


Best Practices to Avoid Build Issues

Follow this checklist:

  • Fix all warnings in development

  • Test routing with page refresh

  • Verify environment variables

  • Check asset paths

  • Test production build locally

  • Avoid relying on dev-only behavior

This prevents 90% of “works locally but not in production” issues.


When to Use Development vs Production Mode

ModeUse Case
DevelopmentCoding, debugging, learning
ProductionDeployment, real users

Never deploy a React app using development mode.


Conclusion

React development mode and production mode serve very different purposes. Development mode helps you write better code, while production mode delivers fast, optimized experiences to users.

Understanding the differences between these two modes helps you:

  • Debug smarter

  • Deploy with confidence

  • Avoid common production surprises

Once you master this, deploying React apps becomes far less stressful.

Comments

Popular posts from this blog

Why Your React App Shows a Blank Page (And How to Fix It)

Introduction One of the most frustrating problems when working with React JS is opening your app and seeing… nothing . No error message. No UI. Just a blank page . This issue happens frequently, especially after deployment or routing changes. In this article, we’ll explain why React apps show a blank page , the most common causes , and how to fix them step by step . What a “Blank Page” Usually Means in React A blank page usually means: React failed to render the UI JavaScript error stopped execution Routing or build configuration is broken Most of the time, the issue is not React itself , but how the app is configured. 1. JavaScript Error in the Console The first thing you should always check is the browser console. How to Check Open the app Right click → Inspect Open the Console tab If you see a red error message, React stopped rendering. Common Examples Cannot read property of undefined Unexpected token Module not found Fix Read the...

Nginx vs Apache: Which Web Server Should You Use on a VPS?

Introduction When setting up a VPS for hosting websites or applications, one of the first decisions you’ll face is choosing a web server. The two most popular options are Nginx and Apache . Both are powerful, widely used, and production-ready — but they work very differently. In this article, we’ll compare Nginx vs Apache , explain how each one works , highlight their strengths and weaknesses , and help you decide which web server is better for your VPS setup . What Is a Web Server? A web server is software that: Receives requests from browsers Processes those requests Serves HTML, CSS, JavaScript, or API responses Popular web servers include: Nginx Apache LiteSpeed Caddy Among them, Nginx and Apache dominate most VPS environments . What Is Apache? Apache has been around since the mid-1990s and was the most widely used web server for many years. How Apache Works Apache uses a process-based or thread-based model : Each request is handled by a p...