Skip to content
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

Minifier too agressive deletes used code #53723

Closed
1 task done
santialbo opened this issue Aug 8, 2023 · 2 comments · Fixed by #53831
Closed
1 task done

Minifier too agressive deletes used code #53723

santialbo opened this issue Aug 8, 2023 · 2 comments · Fixed by #53831
Labels
bug Issue was opened via the bug report template. linear: turbopack Confirmed issue that is tracked by the Turbopack team. locked SWC Related to minification/transpilation in Next.js.

Comments

@santialbo
Copy link

santialbo commented Aug 8, 2023

Verify canary release

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

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.5.0: Thu Jun  8 22:22:20 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6000
    Binaries:
      Node: 18.16.0
      npm: 9.5.1
      Yarn: 1.22.19
      pnpm: N/A
    Relevant Packages:
      next: 13.4.14-canary.0
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0
      typescript: N/A
    Next.js Config:
      output: N/A

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

SWC minifier (swcMinify: true), SWC transpilation

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

https://github.com/santialbo/next-swc-issue

To Reproduce

Create a basic next app

npx create-next-app@latest nextjs-blog --use-npm --example "https://github.com/vercel/next-learn/tree/master/basics/learn-starter"

Create a /pages component like the following

export default function Home() {
  return (
    <div>{foo.a}</div>
  )
}

const foo = {
  get a() {
    return `a ${this.b}`;
  },
  get b() {
    return `b`;
  }
}

Run yarn build and inspect .next/chunks/pages/{chunk of the used page}, the following will be generated:

(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[405],{5557:function(n,t,u){(window.__NEXT_P=window.__NEXT_P||[]).push(["/",function(){return u(6616)}])},6616:function(n,t,u){"use strict";u.r(t),u.d(t,{default:function(){return r}});var e=u(5893);function r(){return(0,e.jsx)("div",{children:c.a})}let c={get a(){return"a ".concat(this.b)}}}},function(n){n.O(0,[774,888,179],function(){return n(n.s=5557)}),_N_E=n.O()}]);

The previous foo object gets compiled into

let c={get a(){return"a ".concat(this.b)}}

Notice property get b is missing! The resulting string is a undefined instead of a b;

Describe the Bug

The minifier is too agressive eliminating dead code which is not actually dead.

I noticed this error in my codebase when I upgraded from 13.4.9 to 13.4.13

Expected Behavior

Don't delete actually used property.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

NEXT-1502

@santialbo santialbo added the bug Issue was opened via the bug report template. label Aug 8, 2023
@github-actions github-actions bot added area: SWC Minify SWC Related to minification/transpilation in Next.js. labels Aug 8, 2023
@balazsorban44 balazsorban44 added the linear: next Confirmed issue that is tracked by the Next.js team. label Aug 8, 2023
@balazsorban44
Copy link
Member

Looks like it's a regression that slipped in via #52371, we are looking into it, thanks for reporting!

@balazsorban44 balazsorban44 added linear: turbopack Confirmed issue that is tracked by the Turbopack team. and removed linear: next Confirmed issue that is tracked by the Next.js team. labels Aug 8, 2023
@kodiakhq kodiakhq bot closed this as completed in #53831 Aug 11, 2023
kodiakhq bot pushed a commit that referenced this issue Aug 11, 2023
### What?

Update swc crates to swc-project/swc@54f38cb

### Why?

To apply minifier bugfixes.

### How?

Closes WEB-1358
Fixes #53723

---

turbopack counterpart: vercel/turborepo#5699
@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. linear: turbopack Confirmed issue that is tracked by the Turbopack team. locked SWC Related to minification/transpilation in Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants