vercel / next.js

The React Framework
https://nextjs.org
MIT License
126.82k stars 26.95k forks source link

[backport request] Backport fix of an already-fixed bug of next-swc #66085

Open tjx666 opened 5 months ago

tjx666 commented 5 months ago

Link to the code that reproduces this issue

https://stackblitz.com/edit/nextjs-wzyqzn?file=app%2Fpage.tsx

To Reproduce

just open the stackblize online reproduce

Current vs. Expected behavior

class Father {
  static instance = {};

  static register() {
    return (target) => {
      class Wrapper extends target {
        constructor(props) {
          super({
            ...props,
          });
        }
      }

      this.instance = new Wrapper();
    };
  }

  private _a = 1;

  constructor() {
    this._a = 2;
  }
}

@Father.register()
class Son {}

console.log(Father.instance._a); // 1, but why ???
image image

expect

should compile correct

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: Ubuntu 20.04.0 LTS Wed May 22 2024 23:45:04 GMT+0800 (中国标准时间)
Binaries:
  Node: 18.20.3
  npm: 10.2.3
  Yarn: 1.22.19
  pnpm: 8.15.6
Relevant Packages:
  next: 14.1.0
  eslint-config-next: 13.5.1
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.2.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

SWC

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

The latest canary version fix this issue, but I can find a good way to fix it now.

I want to use canary but it require react19. I try use yarn1 resolution to lock the next swc version, but yarn1 seems can't correctly deal with resolution with optionalDependencies:

image

So, I thing the best method way to fix this is the nextjs official release a new 14.x version.

I think the compile error is a serious error and cost me one day to locate it.

more context:

  1. https://x.com/YuTengjing/status/1793270230531395826
  2. https://github.com/swc-project/swc/pull/8835
kdy1 commented 5 months ago

So you are requesting a backport?

tjx666 commented 5 months ago

@kdy1 I recently upgrade my company project next from 12 to 14, next12 no this bug. The latest nextjs still has this bug but canary version had fixed it.

I don't know when the next will release the new version to fix it, But now there is no good way to fix it.

kdy1 commented 5 months ago

Yeap I understood. If we want to publish a new version that uses react@18 and recent SWC, we need to revert many commits before publishing and it should be a backport

tjx666 commented 5 months ago

I see that issue is related with swc loose setting, any way to config swc not to use losse?

ref: https://github.com/swc-project/swc/issues/8830#issuecomment-2044727551

kdy1 commented 5 months ago

next-swc does not use loose mode

tjx666 commented 4 months ago

@kdy1 I see there is a new 14.x update, but this issue is still not fixed

Edit by maintainer bot: Comment was automatically minimized because it was considered unhelpful. (If you think this was by mistake, let us know). Please only comment if it adds context to the issue. If you want to express that you have the same problem, use the upvote 👍 on the issue description or subscribe to the issue for updates. Thanks!

kdy1 commented 4 months ago

https://github.com/vercel/next.js/blob/v14.2.4/Cargo.lock#L5431

It's 0.90.30 and but the fix is 0.90.31