Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minified React Errors in production #50245

Closed
1 task done
gaurishhs opened this issue May 24, 2023 · 81 comments
Closed
1 task done

Minified React Errors in production #50245

gaurishhs opened this issue May 24, 2023 · 81 comments
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template. please add a complete reproduction The issue lacks information for further investigation

Comments

@gaurishhs
Copy link

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: x64
      Version: Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:22 PDT 2022; root:xnu-8020.121.3~4/RELEASE_X86_64
    Binaries:
      Node: 18.16.0
      npm: 9.5.1
      Yarn: N/A
      pnpm: 8.5.1
    Relevant packages:
      next: 13.4.3
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0
      typescript: N/A

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true)

Link to the code that reproduces this issue or a replay of the bug

https://github.com/gaurishhs/Portfolio

To Reproduce

git clone https://github.com/gaurishhs/Portfolio.git
pnpm i
vc 

Describe the Bug

I'm using next-themes along with app directory and i get these Minified react errors in the production deployment only on Vercel. These errors are not there during development mode or if i use vc deploy
Screenshot 2023-05-24 at 8 24 41 AM

Expected Behavior

No such errors

Which browser are you using? (if relevant)

Brave Browser

How are you deploying your application? (if relevant)

Vercel

@gaurishhs gaurishhs added the bug Issue was opened via the bug report template. label May 24, 2023
@github-actions github-actions bot added the area: app App directory (appDir: true) label May 24, 2023
@ArmanNisch
Copy link

ArmanNisch commented Jun 8, 2023

I just installed a new, 100% untouched version of next.js, and this error is present.

The steps I followed:
Step 1) I ran npx create-next-app@latest and then

Step 2) change the next.config.js as follows:

/** @type {import('next').NextConfig} */
const nextConfig = {
    output: 'export',
    // Optional: Add a trailing slash to all paths `/about` -> `/about/`
    trailingSlash: true,
    // Optional: Change the output directory `out` -> `dist`
    distDir: 'dist',
}

module.exports = nextConfig

Step 3) ran the next build command.

Step 4) cd to /dist and then I served the files with a local static site server (I used browsersync).

The Errors I see:

  1. x5 Uncaught Error: Minified React error #418
  2. x1 Uncaught Error: Minified React error #423

There has been an ongoing discussion around this issue since Dec 2022; not sure why a ticket was not created: #43921

This issue might be a react 18 issue as GatsbyJs users report a similar issue: gatsbyjs/gatsby#36232

Update: To rule out the possibility that a browser plugin was causing this issue, I viewed the next site in Google Chrome incognito and Safari incognito (I have no extensions enabled in incognito). Across both browsers, the exact same errors are still present.

@gaurishhs
Copy link
Author

Quite disappointing to see that this is a growing issue and this has been open for 2 weeks yet no official response.

@icyJoseph
Copy link
Contributor

icyJoseph commented Jun 8, 2023

Well I gave it a go with @ArmanNisch 's approach, except with serve rather than browsersync, and I see no issue what so ever.

Do yo use these when running the dev mode?

@gaurishhs
Copy link
Author

gaurishhs commented Jun 8, 2023 via email

@icyJoseph
Copy link
Contributor

Yeah, well you seemed to agree with @ArmanNisch 's approach, but you two are most likely looking at two wildly different issues, that manifest through the same error message.

I think in @gaurishhs 's case there's two potential issues:

   <script type="b06cea64085c747784d6e62e-text/javascript">
            !function(){try{var d=document.documentElement,c=d.classList;c.remove('light','dark');var e=localStorage.getItem('theme');if('system'===e||(!e&&true)){var t='(prefers-color-scheme: dark)',m=window.matchMedia(t);if(m.media!==t||m.matches){d.style.colorScheme = 'dark';c.add('dark')}else{d.style.colorScheme = 'light';c.add('light')}}else if(e){c.add(e|| '')}if(e==='light'||e==='dark')d.style.colorScheme=e}catch(e){}}()
        </script>

This script from next-themes is sent by the server like this, but then it transforms into:

 <script>
            !(function () {
                try {
                    var d = document.documentElement,
                        c = d.classList;
                    c.remove("light", "dark");
                    var e = localStorage.getItem("theme");
                    if ("system" === e || (!e && true)) {
                        var t = "(prefers-color-scheme: dark)",
                            m = window.matchMedia(t);
                        if (m.media !== t || m.matches) {
                            d.style.colorScheme = "dark";
                            c.add("dark");
                        } else {
                            d.style.colorScheme = "light";
                            c.add("light");
                        }
                    } else if (e) {
                        c.add(e || "");
                    }
                    if (e === "light" || e === "dark") d.style.colorScheme = e;
                } catch (e) {}
            })();
        </script>

And then that the server sends viewbox on SVG's, rather than viewBox.

Screenshot 2023-06-08 at 19 19 31

Also the email is somehow mangled, but perhaps that's done through a script or something. Or maybe it's just that your latest deploy is not up to date.

@gaurishhs
Copy link
Author

gaurishhs commented Jun 8, 2023 via email

@icyJoseph
Copy link
Contributor

Yeah like I've debugged it and stepping through I see a frame where the UI goes to light mode, and then the errors come in, and then it goes dark mode again. Why doesn't it happen locally though, that's really odd.

@icyJoseph
Copy link
Contributor

Here you go, but I am still not sure, exactly what breaks

Screen.Recording.2023-06-08.at.19.37.41.mov

@icyJoseph
Copy link
Contributor

One more monitoring the HTML tag attributes.

Screen.Recording.2023-06-08.at.19.39.46.mov

@icyJoseph
Copy link
Contributor

And btw, this could also be a coincidence, as if React is done doing a bunch of work, and paints, and also prints errors. Doesn't necessarily mean the next-themes is culprit, at least not 100%. We have some hints yes, but not conclusive yet.

Do you see this error in the Vercel previews? I wonder if, somehow, cloudflare is the issue? That'd be wild, but within the margin of errors I've seen.

@gaurishhs
Copy link
Author

gaurishhs commented Jun 9, 2023 via email

@icyJoseph
Copy link
Contributor

Mmm well, all the more reason to think something might be happening on Cloudflare. Do you know if you have HTML rewriter, or any setting activated in Cloudflare that could be making changes to your HTML?

@gaurishhs
Copy link
Author

gaurishhs commented Jun 10, 2023

Mmm well, all the more reason to think something might be happening on Cloudflare. Do you know if you have HTML rewriter, or any setting activated in Cloudflare that could be making changes to your HTML?

I have enabled Cloudflare rocket loader and some scripts do get loaded from /cdn-cgi which is handled by cloudflare so i guess yeah, Cloudflare is making changes to the HTML
Screenshot 2023-06-10 at 10 52 39 AM

@returnednull
Copy link

please guys this is such a bullshit error it can happen anytime anywhere basically, in complex web apps. we follow best practices of our stack but its sucks on both UX/DX sides. error is basically we are doing some calculations on server and we are doing same on client on hydrating, if results dont adds up, we throw error. it doesn't make any sense, we don't have to consider hydration of every server rendered value. we dont use simple fetch() and prop passing on our tutorial todo app. we heavily depend other global state and data fetching libraries. we cant trust client devices. for example if we have to use basic client releated feature for example Intl APIs/Web Senser APIs/global state persistence/optimistic data fetching etc.. we have to hydrate as null and show suspense, and initialize it as second render. this is not well documented or tooled workflow as its sucks on user side we dont consider this. main thread completely blocking for a while if hydration occurs. we cant wrap everything is suspense or we cant make sure of every 3rd party lib./framework/client compatiable for us. this is painful job, sometimes I miss my getserversideprops days. this is not an issue back then. these new rsc approach is good but I think tooling and community around it sucks. sometimes I feel like I have to invest on another frontend framework/library.

@DzTheRage
Copy link

DzTheRage commented Jun 15, 2023

131k of these errors in Bugsnag since April 16th.

Potential causes I've read while debugging this.

  • h1 tag inside of p tag
  • window usage
  • date mismatch
  • dynamic imports

@wub
Copy link

wub commented Jun 15, 2023

We're getting the same issues with Remix, and only on Vercel. Hard to pin down!

@DzTheRage
Copy link

Our issue seems to be resolved after removing new Date() from inside render and putting that logic into a useEffect.

@icyJoseph
Copy link
Contributor

icyJoseph commented Jun 19, 2023

@DzTheRage japp date and locales can cause this issue easily. For example a call to toLocaleUppercase can break all hell loose...

For these though, the supressHydrationWarning flag should suffice, https://react.dev/reference/react-dom/hydrate#suppressing-unavoidable-hydration-mismatch-errors

@lopugit
Copy link

lopugit commented Jun 26, 2023

@wub Getting this on a Remix + React 18 + Vercel deployment too.

Completely fresh project with only a root.tsx and index.tsx file with Chakra UI installed

https://thingtime.com

Edit:

I've tracked this down to the Vimeo Screen Recorder Chrome Extension. Although I was getting this error on my friend's iPhone too which wouldn't have had this extension.

Disabling the extension fixes the issue on my Laptop.

Screenshot 2023-06-27 at 8 33 21 am

This even happens on the official Vercel Remix Starter deployment

https://remix-run-template.vercel.app/

@lopugit
Copy link

lopugit commented Jun 27, 2023

Ok so this comes down to React 18 not being able to handle hydration errors very gracefully.

The solution seems to be to make a entry.client.tsx with the following which will use the React 17 hydrate function instead of the React 18 hydrateRoot function.

import { hydrate } from 'react-dom'
// import { RemixBrowser } from "remix";
import { RemixBrowser } from '@remix-run/react'
hydrate(<RemixBrowser />, document)

@aprilmintacpineda
Copy link

I have the same problem currently. In my case, I get 4 errors

next.config.js

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: false,
  output: 'export',
  transpilePackages: ['@internal/*']
};

module.exports = nextConfig;

image

I run next build then I publish it in s3 bucket behind cloudfront.

@gaurishhs
Copy link
Author

gaurishhs commented Jul 4, 2023 via email

@OrionStark
Copy link

I got the issue too

@shahryarjb
Copy link

I have 3 errors you can see https://noelhz.com/, it should be noted I did not use any time or etc, it is a simple site.

I deployed it on CloudFlare page, idk how to fix it

/** @type {import('next').NextConfig} */
const nextConfig = {
  basePath: "",
  reactStrictMode: true,
  images: { unoptimized: true },
  experimental: { runtime: 'edge'}
}

module.exports = nextConfig

Screenshot 2023-07-06 at 00 58 17

@martianacademy
Copy link

Is issue resolved

@shahryarjb
Copy link

@martianacademy no!

@ger86
Copy link

ger86 commented Jul 20, 2023

The same may happen if you are using i18next and react-i18next libraries and a backend to load the translations. Remember to surround with <Suspense>

@dmitkov28
Copy link

Same here. Pinning Next to 14.1.4 seems to solve this for now.

@samcx samcx added the please add a complete reproduction The issue lacks information for further investigation label Apr 17, 2024
Copy link
Contributor

We cannot recreate the issue with the provided information. Please add a reproduction in order for us to be able to investigate.

Why was this issue marked with the please add a complete reproduction label?

To be able to investigate, we need access to a reproduction to identify what triggered the issue. We prefer a link to a public GitHub repository (template for App Router, template for Pages Router), but you can also use these templates: CodeSandbox: App Router or CodeSandbox: Pages Router.

To make sure the issue is resolved as quickly as possible, please make sure that the reproduction is as minimal as possible. This means that you should remove unnecessary code, files, and dependencies that do not contribute to the issue. Ensure your reproduction does not depend on secrets, 3rd party registries, private dependencies, or any other data that cannot be made public. Avoid a reproduction including a whole monorepo (unless relevant to the issue). The easier it is to reproduce the issue, the quicker we can help.

Please test your reproduction against the latest version of Next.js (next@canary) to make sure your issue has not already been fixed.

If you cannot create a clean reproduction, another way you can help the maintainers' job is to pinpoint the canary version of next that introduced the issue. Check out our releases, and try to find the first canary release that introduced the issue. This will help us narrow down the scope of the issue, and possibly point to the PR/code change that introduced it. You can install a specific version of next by running npm install next@<version>.

I added a link, why was it still marked?

Ensure the link is pointing to a codebase that is accessible (e.g. not a private repository). "example.com", "n/a", "will add later", etc. are not acceptable links -- we need to see a public codebase. See the above section for accepted links.

What happens if I don't provide a sufficient minimal reproduction?

Issues with the please add a complete reproduction label that receives no meaningful activity (e.g. new comments with a reproduction link) are automatically closed and locked after 30 days.

If your issue has not been resolved in that time and it has been closed/locked, please open a new issue with the required reproduction.

I did not open this issue, but it is relevant to me, what can I do to help?

Anyone experiencing the same issue is welcome to provide a minimal reproduction following the above steps. Furthermore, you can upvote the issue using the 👍 reaction on the topmost comment (please do not comment "I have the same issue" without reproduction steps). Then, we can sort issues by votes to prioritize.

I think my reproduction is good enough, why aren't you looking into it quicker?

We look into every Next.js issue and constantly monitor open issues for new comments.

However, sometimes we might miss one or two due to the popularity/high traffic of the repository. We apologize, and kindly ask you to refrain from tagging core maintainers, as that will usually not result in increased priority.

Upvoting issues to show your interest will help us prioritize and address them as quickly as possible. That said, every issue is important to us, and if an issue gets closed by accident, we encourage you to open a new one linking to the old issue and we will look into it.

Useful Resources

@samcx
Copy link
Member

samcx commented Apr 17, 2024

@gaurishhs just adding the please add a complete reproduction label for info but we would love to take a look at this if you (or anybody in this thread) can add a :repro: we can take a look at!

@batmanSix
Copy link

这种情况在 14.2.0 中再次发生。 image

replace nextjs version 14.1.4 A self-test is available to solve this problem

@gaurishhs
Copy link
Author

gaurishhs commented Apr 18, 2024

@gaurishhs just adding the please add a complete reproduction label for info but we would love to take a look at this if you (or anybody in this thread) can add a :repro: we can take a look at!

I have moved that app away from Next.js so i cannot provide a Repro for it now but hopefully somebody else can.

@hamlim
Copy link
Contributor

hamlim commented Apr 18, 2024

For folks that were running into the Minified React Error #306 after upgrading to 14.2.0 or 14.2.1 - this PR (that was included in 14.2.2) seemed to resolve the issue for us: #64558!

In our case, we had the following in one of our layout.tsx files:

import {Suspense} from 'react';
// This library is compiled down to CJS
// The library's entrypoint includes the `"use client";` directive
import SomeComponent from 'an-internal-library';

export default function Layout({children}) {
  return (
    <>
      {children}
      <Suspense>
        <SomeComponent />
      </Suspense>
    </>
  );
}

@waza-ari
Copy link

We had the same issue with 14.2.2, downgrading to 14.1.4 does resolve the issue for us. I'll try to provide a reproduction example tomorrow.

@pablojsx
Copy link

pablojsx commented Apr 24, 2024

emmmmm just had this issue, IN MY CASE I was importing a mui icon into a server component.. in my case it was error #306

@wilson-webdev
Copy link

wilson-webdev commented Apr 27, 2024

This issue has been resolved for me since 14.2.3

@samcx
Copy link
Member

samcx commented May 1, 2024

@waza-ari any luck with that :repro: ? Also, I recommend trying the latest canary to see if it's still present there, it seems it may have been :fixed: according to the above comment.

@waza-ari
Copy link

waza-ari commented May 1, 2024

@samcx sorry, I should've updated this here, I did get caught up in other work. In our case it also was a MUI import that caused this issue. Also, the error description is quite generic and I have the feeling many (potentially similar) issues get mixed up (same for me probably).

So to our case:

# This one is broken and causes errors in production (but works in dev mode)
import Grid from '@mui/material/Unstable_Grid2';

# This one worked in both cases
import Grid from '@mui/material/Unstable_Grid2/Grid2';

Which is a bit weird as the first import is according to their docs. Will try (hopefully on the weekend) to repro and potentially test with canary as well, hope I can keep my promise this time.

@kukulkanParanoici
Copy link

I had these same issues only in production. It seems there can be potentially a lot of different reasons for it to happen, like locale management, date usage during render, etc. In my case it was some slight differences in space and comment handling in the html caused by cloudflares "Auto Minify" feature, which is deprecated and will soon be not available anymore, but that caused the difference between client and server html.

@jeffzhkw
Copy link

I had the same issue for me when using 14.2.1. I am unable to locate the actual cause, but upgrading to 14.2.3 works for me.

@avremel
Copy link

avremel commented May 22, 2024

We recently upgraded from 12.3.4 to 14.2.3 and experienced the same issue: Intermittent client side errors only in the production build, not in the dev environment.

@pogran

This comment has been minimized.

@JClackett
Copy link
Contributor

JClackett commented Jun 20, 2024

How are we supposed to find the cause of the error when it only happens in production haha? im getting blasted with sentry errors relating to hydration errors, and I load up an exact same copy of the database, same timezone, same user account and its fine in dev, have tried turbo as well. Im not doing any <p>'s in <p>'s or any weird html stuff, though I would have thought dev would pick this up?

@Nirbhay007

This comment has been minimized.

@saulve
Copy link

saulve commented Jun 26, 2024

I finally managed to clear these errors. Sharing the solution in case somebody else find it useful. In my case the issue was as follows:

  1. I'm using next-intl for translations which required me to put my app under the dynamic [locale] route.
  2. The main app html is generated in LocaleLayout
  3. I also had a global not-found.tsx, which required me to create a RootLayout in the project root.
  4. I was dynamically rendering Vercel's <Analytics /> and <SpeedInsights /> inside the RootLayout:
import { PropsWithChildren } from "react";
import { Analytics } from "@vercel/analytics/react";
import { SpeedInsights } from "@vercel/speed-insights/next";

// Since we have a root `not-found.tsx` page, a layout file
// is required, even if it's just passing children through.
export default function RootLayout({ children }: PropsWithChildren) {
  return (
    <>
      {process.env.NODE_ENV === "production" && <Analytics />}
      {process.env.NODE_ENV === "production" && <SpeedInsights />}
      {children}
    </>
  );
}

Dynamically rendering <Analytics /> and <SpeedInsights /> in RootLayout is what caused the problem since <html> element was not available there. Once I moved the rendering of these components to my LocaleLayout the errors stopped.

To clarify I had these errors both when running npm run build locally and when deployed on Vercel.

@Charles953
Copy link

We recently upgraded from 12.3.4 to 14.2.3 and experienced the same issue: Intermittent client side errors only in the production build, not in the dev environment.

I have the same problem, have you solved it?

@arifikhsan

This comment has been minimized.

@claudiofrs
Copy link

I also encounter the same error. Not sure what's happening. Mine was just a simple route using pages setup, checked by removing all commented line, removing all HTML tags, but no avail. dev works fine tho...

@jimmi2051
Copy link

My packages -

"next": "14.2.5"
"react": "18.2.0",

and still have the same problem.

Script I'm using to run on Production

NODE_ENV=production npm run build
NODE_ENV=production npm run start

@bhuwang279
Copy link

bhuwang279 commented Jul 22, 2024

I had the same issue. App was working fine in development but facing issue in production or local build. The only thing seems to work was to change the route name. For eg. my route folder name was "luxury-camp" and changing it to "camp" fixed the issue. But now the problem is marketing team wants "luxury-camp" in route

@JClackett
Copy link
Contributor

I had the same issue. App was working fine in development but facing issue in production or local build. The only thing seems to work was to change the route name. For eg. my route folder name was "luxury-camp" and changing it to "camp" fixed the issue. But now the problem is marketing team wants "luxury-camp" in route

There's no way that that is the cause, gota be coincidence

@bhuwang279
Copy link

I had the same issue. App was working fine in development but facing issue in production or local build. The only thing seems to work was to change the route name. For eg. my route folder name was "luxury-camp" and changing it to "camp" fixed the issue. But now the problem is marketing team wants "luxury-camp" in route

There's no way that that is the cause, gota be coincidence

I hope its coincidence, there's no way i can debug this. I can change the route name to anything and it works but its just "luxury-camp" route name raising the issue.

@minusplusmultiply
Copy link

Just today - out of nowhere, no updates/changes to my site in about 10 days, and now I'm getting a bunch of these errors too. -_-

@samcx
Copy link
Member

samcx commented Aug 8, 2024

Hi everyone—

I will be moving this to our discussions.

I think it's likely that there a several of ways to arrive to this issue, but without a :repro:, there isn't much we can do about it.

If you are able to figure out how to minimally reproduce the error, I encourage you to submit a new bug report so we can take a closer look!

@vercel vercel locked and limited conversation to collaborators Aug 8, 2024
@samcx samcx converted this issue into discussion #68689 Aug 8, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template. please add a complete reproduction The issue lacks information for further investigation
Projects
None yet
Development

No branches or pull requests