Does Next.js15 Support Pages Router with React 18?

Next.js 15 has been designed to work with both React 18 and React 19, ensuring developers can benefit from its enhancements without being forced to upgrade React immediately. This backward compatibility was added to provide flexibility and a smoother transition path.

Why Maintain Compatibility with React 18?

Next.js 15 retains support for the Pages Router with React 18 based on community feedback:

  • Seamless Upgrades: Developers can start using new features in Next.js 15 without the need to switch to React 19 instantly.
  • Incremental Transitions: This setup allows developers to decide when to upgrade to React 19, minimizing disruptions.
  • Flexibility for Large Projects: Large applications can continue using React 18 while testing compatibility with React 19 in smaller modules.

How to Configure Pages Router with React 18

1. Set Up Next.js 15 with React 18

To use Next.js 15 with React 18, update your package.json as follows:

"dependencies": {
  "next": "15.0.0",
  "react": "18.2.0",
  "react-dom": "18.2.0"
}

This configuration keeps your application running on React 18 while using the new features in Next.js 15.

2. Integrate Changes for React 19 Later

While Next.js 15 introduces the App Router with React 19, the Pages Router can still run smoothly on React 18. You can plan and test your transition to React 19 while keeping your main codebase stable.

Important Considerations

Though it is technically feasible to run both Pages Router with React 18 and App Router with React 19 in the same project, this is not recommended due to:

  • Typings Inconsistencies: There might be mismatched types between the two versions.
  • Inconsistent APIs: Differences in underlying APIs could cause unpredictable behavior.

Real-World Use Case

Imagine a large e-commerce platform using the Pages Router with React 18:

  • By upgrading to Next.js 15, the team can access improvements like optimized SSR and caching enhancements without making immediate changes to the React version.
  • Developers can gradually test and implement React 19 in isolated parts of the app, ensuring stability before a full migration.

FAQs

Q1: Can I use the App Router with React 19 while keeping the Pages Router on React 18?

While technically possible, this approach may introduce issues like inconsistent behavior and mismatched API logic.

Q2: Why does Next.js 15 still support React 18?

Supporting React 18 in the Pages Router allows developers to adopt Next.js 15 improvements without requiring an immediate React upgrade. This helps maintain stability while preparing for the full transition.

Q3: How does Next.js 15 improve performance with React 18?

Next.js 15 brings improvements like better SSR and caching optimizations, which work seamlessly with React 18, ensuring a smoother experience for Pages Router users.

Q4: Should I upgrade to React 19 now?

Upgrading to React 19 is not mandatory. You can continue using React 18 with the Pages Router and adopt React 19 at your own pace.

Summary

Next.js 15 offers backward compatibility with React 18, enabling developers to enjoy new features while gradually transitioning to React 19. This approach ensures flexibility and control over the upgrade process, allowing for a more stable and predictable migration experience.

Clap here if you liked the blog