Next.js: deploying to Vercel causes conditional statements to evaluate incorrectly

Created on 25 Aug 2020  路  10Comments  路  Source: vercel/next.js

Bug report

Describe the bug

When rendering a page using Incremental Static Regeneration a *conditional statement is erroneously applied to the wrong element.

*I'm referring to conditional rendering expressions of the following form:

<div>
   {true && <div />}
   <div />
</div>

To Reproduce

  1. go to my repo, https://github.com/AHBruns/vercel-repro
  2. clone it, npm install, and *npm run dev
  3. inspect element
  4. you'll see the following, which is correct:
<div>
   <div class="SHOW"></div>
</div>
  1. deploy the repo to Vercel
  2. go to the deployed site
  3. inspect element
  4. you'll see the following, which is incorrect:
<div>
   <div class="NO_SHOW"></div>
</div>

*npm run build && npm run start yields the same problem

Expected behavior

A single div with the class SHOW should be added to the DOM regardless of the environment.

System information

  • Version of Next.js: v9.5.2
  • Version of Node.js: v14.3.0
bug 3 needs investigation

Most helpful comment

Did some investigating:

  • Added a next.config.js with target: 'experimental-serverless-trace'
  • Ran next build
  • The console.log in _app logged out /404 which is unexpected

So this is definitely a bug in Next.js, we'll fix it 馃檹

All 10 comments

Could you please upgrade to next@canary and try this again? We've fixed a lot of CSS-related things in the newest canary.

Could you please upgrade to next@canary and try this again? We've fixed a lot of CSS-related things in the newest canary.

Okay. Just did this, and the problem persists.

I should add that this isn't really CSS related. It seems like the conditional statement is being applied to the wrong element somehow. The CSS was just to illustrate that.

Thanks, we'll take a peek soon!

My original example had a lot going on. I made a clean new repo and was able to build up to triggering the bug.

reproduction repo

It seems to be related to rendering pages that use Incremental Static Regeneration. I still can't identify why the conditional is being applied to the wrong element because it's a completely silent error (AFAIK even if the boolean was flipped the result I'm getting from Vercel would still be impossible).

Interestingly, the only valid evaluations of the following code

image

are:

<div>
   <div class="SHOW"></div>
</div>

or

<div>
   <div class="NO_SHOW"></div>
   <div class="SHOW"></div>
</div>

However, the Vercel page is the following:

image

which should be impossible. Hence, this probably has to be a problem in either how Vercel transpiles my code or how the browser interprets the transpiled code. Because I've tested a couple different browsers and found the same problem across all of them, it seems to me that Vercel's transpiler likely has a bug.

My original example had a lot going on. I made a clean new repo and was able to build up to triggering the bug.

reproduction repo

It seems to be related to rendering pages that use Incremental Static Regeneration. I still can't identify why the conditional is being applied to the wrong element because it's a completely silent error (AFAIK even if the boolean was flipped the result I'm getting from Vercel would still be impossible).

Interestingly, the only valid evaluations of the following code

image

are:

<div>
   <div class="SHOW"></div>
</div>

or

<div>
   <div class="NO_SHOW"></div>
   <div class="SHOW"></div>
</div>

However, the Vercel page is the following:

image

which should be impossible. Hence, this probably has to be a problem in either how Vercel transpiles my code or how the browser interprets the transpiled code. Because I've tested a couple different browsers and found the same problem across all of them, it seems to me that Vercel's transpiler likely has a bug.

Rewrote the bug report to reference this reproduction.

Did some investigating:

  • Added a next.config.js with target: 'experimental-serverless-trace'
  • Ran next build
  • The console.log in _app logged out /404 which is unexpected

So this is definitely a bug in Next.js, we'll fix it 馃檹

Did some investigating:

  • Added a next.config.js with target: 'experimental-serverless-trace'

  • Ran next build

  • The console.log in _app logged out /404 which is unexpected

So this is definitely a bug in Next.js, we'll fix it 馃檹

Sounds good. Thank you for the quick response!

Hi, this should be fixed in v9.5.4-canary.16 of Next.js please upgrade and give it a try!

Thanks a million! I'll confirm everything is fixed when I get home evening.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

YarivGilad picture YarivGilad  路  3Comments

havefive picture havefive  路  3Comments

ghost picture ghost  路  3Comments

knipferrc picture knipferrc  路  3Comments

rauchg picture rauchg  路  3Comments