Skip to content

Bug: ESLint rules flag Date.now as an inpure function in a server componentΒ #34834

@paulvanbrenk

Description

@paulvanbrenk

I expect that the the eslint-plugin-react-hooks don't apply to server components.

React version: 19.2

Steps To Reproduce

  1. Introduce an inpure function in a server side component. E.g. the layout in a nextjs app
  2. Run eslint with eslint-plugin-react-hooks@7
  3. Notice error
`Date.now` is an impure function. Calling an impure function can produce unstable results that update unpredictably when the component happens to re-render. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#components-and-hooks-must-be-idempotent).

~/src/inpure-demo/src/app/layout.tsx:25:15
  23 |   children: React.ReactNode;
  24 | }>) {
> 25 |   const now = Date.now();
     |               ^^^^^^^^^^ Cannot call impure function
  26 |   console.log("Rendering RootLayout at", now);
  27 |
  28 |   return (  react-hooks/purity

Link to code example:

https://github.com/paulvanbrenk/inpure-error-nextjs

The current behavior

Error about the inpure function in a server component

The expected behavior

No error

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions