What causes NextJS Warning: "Extra attributes from the server: data-new-gr-c-s-check-loaded... "
Asked Answered
W

16

172

I am getting the following warning from my NextJS Application:

Warning: Extra attributes from the server: data-new-gr-c-s-check-loaded,data-gr-ext-installed,cz-shortcut-listen,data-lt-installed

I don't know why it happens, what is the explanation for this?

Waterscape answered 3/2, 2023 at 15:38 Comment(0)
A
99

Disabling the Grammarly extension solved the problem for me.

Ankledeep answered 15/6, 2023 at 8:24 Comment(2)
It's little strange, disabling both grammarly and colorzilla extentions fixed the issue.Cartier
I had a problem with Grammarly, if someone use other one, need to disable that also for fixing the error.Ankledeep
F
407

This is usually caused by an extension passing these extra attributes with your code when it is executed on the browser trying to interact with the UI, this creates a mismatch between what was rendered on the server and what is rendered on the client.

Extensions similar to Grammarly, ColorZilla and LanguageTool are therefore the cause of this warning, so you have to find out which one is doing this and then disable/configure it to not run on the ports you usually use for development. This is the straightforward fix for the warning, since it is always recommended to avoid extensions in development.


You can find those extra attributes if you inspect the app pure HTML in the Elements section of the devTools

enter image description here

An abbreviation is usually used, like here, lt stands for LanguageTool, gr for Grammaly, and cz for ColorZilla. this can help detect the extension.


Good to know:

You can suppress hydration warnings by setting suppressHydrationWarning to true in the opening <body> tag of the RootLayout:

export default RootLayout({ children }) {
  return (
   <html lang="en">
      <body suppressHydrationWarning={true}>
        {children}
      </body>
    </html>
  )
}

sometimes you have to put it in the opening <html> tag if attributes are added there

<html lang="en" suppressHydrationWarning={true}>

suppresshydrationwarning only works one level deep so if you put it in the <html> element, it won't suppress hydration warnings for the <body> element since it is in a deeper level, that's great! because we don't want to suppress hydration warnings for our server components which are in a deeper level.

Fluorene answered 3/2, 2023 at 17:14 Comment(14)
I added the attribute and it worked. Then I removed the extensions which I've not used since ages and also removed the attribute and it worked too. Thanks for your answer, it helped me clean up my browser : youtube.com/…Isagogics
This suppressHydrationWarning prop fixed it for me, but the error should specify which element is throwing the error. Mine was input, form, and button elements within my server actions (which are experimental still, so that might be the issue).Marivelmariya
@Marivelmariya It is not an error it is a warning, and it will not harm anything, what is more recommended is to disable extensions when developingFluorene
FYI that if you have a class on the HTML tag this will always fire up the error.Infamous
@Moayad.AlMoghrabi in fact better is to disable extensions in dev mode, the second solution is just an alternativeFluorene
I guess you are right, unfortunately for me, disabling Grammarly did not do the trick and I just have like a ton of extensions. so I went to Edge now. However, in production, will I still be seeing these errors?Infamous
@Moayad.AlMoghrabi first it is not an error it is a warning and it is ok to ignore it.Fluorene
Suppressing the hydration warning in a React Server Component architecture is a pretty dumb suggestions. People upvote the biggest sht sadlyLovesome
@Pagenotfound I updated my answer, in docs they mentioned that suppressHydrationWarning only works one level deep so if you put it in the body element it shouldn't affect server components which are in a deeper levelFluorene
Thanks for the comment, in my case, was Grammarly, the fix was to disable the writing checking in localhost (there is an option for this in the plugin)Intra
<body suppressHydrationWarning={true}> works wellMeatman
What about production? What if the final user does have that extension? Will that cause the hydration to also fail but just without showing an error?Crissman
I removed ColorZilla extension from browser, it works, warning disappeared after removing extension, Thanks!!!Blynn
"Adblock Plus - free ad blocker" was causing it for me ....Sosthenna
A
99

Disabling the Grammarly extension solved the problem for me.

Ankledeep answered 15/6, 2023 at 8:24 Comment(2)
It's little strange, disabling both grammarly and colorzilla extentions fixed the issue.Cartier
I had a problem with Grammarly, if someone use other one, need to disable that also for fixing the error.Ankledeep
M
34

Chrome has released a new feature to disable extensions for specific URLs which is great, since this warning seems to just be a development environment issue. Simply put chrome://flags/#extensions-menu-access-control into your Chrome browser to enable this flag and restart Chrome.

After you restart you can click on the extensions icon (in the upper-right corner of your browser), while you are browsing http://localhost:3000 URL, to toggle off your extensions for that URL (only)! No need for the suppressHydrationWarning={true} prop mentioned above.

enter image description here

Marivelmariya answered 9/6, 2023 at 17:29 Comment(2)
This is brilliant, if you're developing on Chrome it's the way to go. It's also a generally useful Chrome tip - thanks for sharing.Sheilahshekel
Thanks for this tip. I had other extensions that I didn't want to use while I am working.Ununa
I
33

disabling ColorZilla extension solved the problem for me.

Inborn answered 20/5, 2023 at 13:18 Comment(0)
H
17

Stop ColorZilla and Grammarly extensions fix my problem.

enter image description here

Update: more extensions that are causing related issues:

  • ColorZilla
  • Grammarly
  • Wikiwand: Wikipedia Modernized
    • Error message: Warning: Extra attributes from the server: style
    • Solution: Change Site Access extension option, from On all sites to on specific sites and enter the URL: https://*.wikipedia.org/*
Hopeless answered 25/7, 2023 at 6:32 Comment(1)
its the grammarly for me. thanksImamate
J
6

In my case Disabling the Grammarly and ColorZilla extension solved the problem.

Johniejohnna answered 21/10, 2023 at 7:9 Comment(0)
A
5

1. Disable extensions

The warning message you're seeing in your JavaScript console, specifically:

Warning: Extra attributes from the server: cz-shortcut-listen...

is related to some attributes being sent from the server that your code might not be handling properly or expecting. This warning is typically not critical and doesn't prevent your application from running, but it's a good practice to address it to ensure that your code remains clean and maintainable.

Temporarily disable browser extensions, except for those required for development in your browser. Browser extensions can sometimes interfere with the behavior of web applications, including altering the content of network requests or injecting additional attributes into HTML elements.

or

2. Prevent hydration

Add suppressHydrationWarning={true} in the opening tag of <body>.

Example: <body className={inter.className} suppressHydrationWarning={true}> your code</body>

Example

Acropolis answered 23/9, 2023 at 17:11 Comment(1)
adding suppressHydrationWarning={true} did not solve the problem for me, rather adding just suppressHydrationWarning on the html tag solved it as metioned in ans by Raja P.B.Flugelhorn
B
3

This warning message indicates that there are some extra attributes on the HTML element that Next.js received from the server that it does not recognize. These attributes are added by various browser extensions, plugins, or toolbars that modify the HTML of the page.

In your case, the attributes data-new-gr-c-s-check-loaded, data-gr-ext-installed, and cz-shortcut-listen are likely being added by one or more browser extensions that are installed in your browser. These attributes are not recognized by Next.js, which is why it is warning you about them.

To get rid of the warning, you can filter out the data-* attributes that next.js does not recognize by using the dangerouslySetInnerHTML prop on the element.

<div 
    dangerouslySetInnerHTML = {{
        __html: htmlString.replace(
            / data-(?!react[\w-]+=)[\w-]+="[^"]*"/g,
            ''
        ),
    }}
/>
Borrero answered 1/4, 2023 at 15:35 Comment(1)
How should I set the dangerouslySetInnerHTML? Should I do it on the <body> tag in the layout.tsx(_app.tsx)? And what should I replace htmlString with since I don't really know where the browser extension could have injected those attributes?Caddaric
O
3

In the app folder and your layout.js file should be like below:

import { Inter } from "next/font/google";
import "./globals.css";

const inter = Inter({ subsets: ["latin"] });

export const metadata = {
  title: "Create Next App",
  description: "Generated by create next app",
};

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body className={inter.className} suppressHydrationWarning={true}>
        {children}
      </body>
    </html>
  );
}
Othello answered 16/11, 2023 at 19:46 Comment(1)
This worked for me by adding suppressHydrationWarning={true} to the body tag as follows : <body className={inter.className} suppressHydrationWarning={true}>{children}</body>Dyarchy
A
3

You should add suppressHydrationWarning on the html tag.

<html lang="en" suppressHydrationWarning>
  <body className={`${inter.className} antialiased`}>
    <ThemeProvider
      attribute="class"
      defaultTheme="system"
      enableSystem
      disableTransitionOnChange
    >
      {children}
    </ThemeProvider>
  </body>
</html>
Appleby answered 26/11, 2023 at 15:7 Comment(0)
C
3

Since this seems to be an issue in development, the following worked for me:

export default function RootLayout({ children }: RootLayoutProps) {
    const isDev = process.env.NODE_ENV === 'development'

    return (
        <html lang="en" suppressHydrationWarning={isDev}>
            <body className={inter.className}>
                <AppProvider>
                    <MainLayout>
                        {children}
                    </MainLayout>
                </AppProvider>
            </body>
        </html>
    )
}

This makes it so you won't have to change your browser settings in every browser you cross test in.

Communalize answered 27/11, 2023 at 1:15 Comment(0)
D
2

There are many Google Extensions for CSS measurements and edits. Most of them are producing errors.

So, after disabling the Measurement extension for the page removed the error.

Dwelling answered 20/11, 2023 at 6:25 Comment(0)
L
2

To avoid this error go to the extensions and switch off your developer mode.

Liebman answered 16/12, 2023 at 5:7 Comment(0)
A
1

I had a problem with the 1688.com plugin that analyzes images in my browser. After disconnecting the problem was solved.

Adjourn answered 21/10, 2023 at 2:14 Comment(0)
B
1

Just wanted to add to this - if anyone is using chrome extension Grammarly or similar extensions, this causes the same issue as it adds these attributes to the <body/> tag

I was getting the same warning and could not figure it out, I thought it was my UI library but then with some help from the community we were able to figure out it from from a chrome extension.

Once I removed Grammarly this warning never came back! Hope this helps anyone else in the same situation that gets directed to this post!

Beaudette answered 11/3 at 2:16 Comment(0)
C
0

also if you are using multiple route layouts with html / body and then you have a top level one also with html / body elements, it will cause this error.

If you are experiencing this, remove all children group layouts html / body elements and just leave them at the top root one

Cominform answered 4/12, 2023 at 9:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.