Coder Social home page Coder Social logo

runsascoded / react-data-table-hydration-bug Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 7.19 MB

Repro of a hydration error in react-data-table-component's Pagination element

Home Page: https://react-data-table-hydration-bug.runsascoded.com/

Dockerfile 1.24% JavaScript 0.94% TypeScript 9.55% CSS 88.26%
nextjs react-data-table-component reactjs

react-data-table-hydration-bug's Introduction

react-data-table-hydration-bug

Repro of a hydration error in react-data-table-component's Pagination element.

When the client window width is < 599px or undefined (as during SSR), "rows per page" in the pagination footer is omitted. This causes a hydration error whenever the client window width is ≥599, as it is omitted on the server but rendered on the client.

Hydration error iff window.innerWidth < 599

Live demo

react-data-table-hydration-bug.runsascoded.com was built and deployed via GitHub Actions, and the error is visible in the dev console:

Page source:

import DataTable from "react-data-table-component";
import ReactMarkdown from "react-markdown";
import fs from "fs";

export function getStaticProps() {
  return { props: { readme: fs.readFileSync("README.md").toString() } }
}

const Index = ({ readme }: { readme: string }) =>
    <div className={"markdown-body"}>
      <ReactMarkdown>{readme}</ReactMarkdown>
      <DataTable
          columns={[ { name: "Str" }, { name: "Num" } ]}
          data={[ { Str: "A", Num: 1 } ]}
          // This line causes a hydration error in the pagination footer "nav" element (iff the
          // browser window is ≥599px wide); commenting this line fixes it.
          pagination
      />
    </div>

export default Index

The error in the dev console links to react#418:

Uncaught Error: Minified React error #418; visit https://reactjs.org/docs/error-decoder.html?invariant=418 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
    at lg (framework-5eea1a21a68cb00b.js:9:46336)
    at i (framework-5eea1a21a68cb00b.js:9:121103)
    at oD (framework-5eea1a21a68cb00b.js:9:99070)
    at framework-5eea1a21a68cb00b.js:9:98937
    at oO (framework-5eea1a21a68cb00b.js:9:98944)
    at ox (framework-5eea1a21a68cb00b.js:9:93983)
    at x (framework-5eea1a21a68cb00b.js:33:1364)
    at MessagePort.T (framework-5eea1a21a68cb00b.js:33:1894)

Local repro

Dev mode gives more details about the error (namely that it occurs in a hierarchy like <nav>…<span> in react-data-table-component's pagination footer):

git clone https://github.com/runsascoded/react-data-table-hydration-bug && cd react-data-table-hydration-bug
pnpm install
npm run dev

localhost:3000 will show something like:

Error text:

Unhandled Runtime Error
Error: Hydration failed because the initial UI does not match what was rendered on the server.
See more info here: https://nextjs.org/docs/messages/react-hydration-error

Expected server HTML to contain a matching <span> in <nav>.

...
  <O>
    <nav>
    ^^^^^
      <O>
        <span>
        ^^^^^^

Commenting out the pagination property avoids the issue; react-data-table-component#649 and this StackOverflow describe the same.


react-data-table-hydration-bug's People

Contributors

ryan-williams avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.