#Using Date throws performance benchmarking error?

1 messages · Page 1 of 1 (latest)

compact dock
#

I have a copyright component which takes the current year using Date API, which throws a mysterious error (included as image attachment of this post) I've never seen before updating to canary. Next.js thinks that I am using Date API for performance benchmarking and warns me that I should be using performance API instead, however I am using Date for displaying the current year.

The linked docs on the topic do not specify how to fix this, and instead just tell me to switch to using performance. Any ideas for fixes?

"use client"

function Copyright() {
  const year = new Date().getFullYear()

  return <span>&copy; {year} Company Name. All rights reserved.</span>
}

Error text:

Error: Route "/" used `new Date()` instead of using `performance` or without explicitly calling `await connection()` beforehand. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time
frosty gateBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

atomic trench
compact dock
#

yes

#
const config = {
  experimental: {
    useCache: true,
    dynamicIO: true,
  },
};

atomic trench
#

nextjs doesn't care that you only need to get the year, as far as nextjs is concerned you are trying to get the exact millisecond count since unix epoch, hence it needs to know whether you want it cached or not

frosty gateBOT
compact dock
#

Caching the component using Date api fixed the issue:

"use cache"

export default async function Footer() {
  return (
    <span>{new Date().getFullYear()}</span>
  )
}