facebook / prop-types

Runtime type checking for React props and similar objects
MIT License
4.48k stars 356 forks source link

PropTypes warnings not displaying in Next.js 14 App Router with React 18.3.1 and React Router DOM #415

Closed zestlee1106 closed 1 month ago

zestlee1106 commented 1 month ago

Bug Report

Description

When using Next.js 14 with the App Router, React 18.3.1, and React Router DOM for routing, PropTypes warnings are not displaying in the console, even in development mode. This issue occurs despite PropTypes being correctly defined and used within components.

Context and Setup

Due to internal constraints, we are using React Router DOM for routing within a single index.js page in our Next.js project. Despite this setup, we expect PropTypes warnings to appear in the developer console when required props are missing.

Steps to Reproduce

  1. Create a new Next.js 14 project using npx create-next-app.

  2. Install prop-types and react-router-dom using npm install prop-types react-router-dom.

  3. Set up routing within a single page.js page using React Router DOM:

    'use client';
    
    import PropTypes from 'prop-types';
    import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';
    
    const MyTitle = ({ name }) => {
      return (
        <div className='title_wrap'>
          <h2>{name}</h2>
        </div>
      );
    };
    
    MyTitle.propTypes = {
      name: PropTypes.string.isRequired,
    };
    
    export default function Home() {
      return (
        <Router>
          <Routes>
            <Route path="/" element={<MyTitle />} />
          </Routes>
        </Router>
      );
    }
  4. Run the project using npm run dev.

  5. Observe that even when the name prop is missing, no PropTypes warning is displayed in the browser's developer console.

Expected Behavior

In development mode, when a required prop is missing, a PropTypes warning should be displayed in the console.

Actual Behavior

No PropTypes warnings are displayed, even when required props are missing.

Additional Context

Please let me know if there is any additional information required or if there are any potential workarounds. Thank you!

ljharb commented 1 month ago

This seems like a create-next-app or next issue, since prop-types hasn’t changed in awhile, and react 19 is the one that drops propType warnings. I’m not sure how this library could cause that.

zestlee1106 commented 1 month ago

@ljharb Thank you for your response. Since I’m using React 18, the prop-type warnings should still be functioning as expected, but unfortunately, they are not. As you suggested, this might indeed be a Next.js issue. I’ll proceed with creating an issue in the Next.js repository with this in mind. I appreciate your guidance!