Async function breaks assigning to new objects in for loops
See original GitHub issueVerify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: win32
Arch: x64
Version: Windows 10 Home
Binaries:
Node: 16.16.0
npm: N/A
Yarn: N/A
pnpm: N/A
Relevant packages:
next: 12.3.1-canary.1
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0
What browser are you using? (if relevant)
Not relevant
How are you deploying your application? (if relevant)
Not relevant
Describe the Bug
Assigning to an object in a for loop inside an async function seems to not work properly. It seems to always assign the final value to be iterated over.
The works
array only has string literals pushed to it, so it works as expect and ends up with ["one", "two", "three"]
.
The broken
array has objects assigned to it, so it is broken and gets [{ input: "three }, { input: "three }, { input: "three }]
even though it’s assigned to with the exact same variable in the exact same for loop.
Everything works as expected when it’s not an async function.
This cannot be reproed on next@12.2.6-canary.8
But can be reproed on next@12.2.6-canary.9
and it remains present in next@canary
as of 14/09/22.
See the README in the attached repro for more details.
Expected Behavior
Both the works
and broken
arrays should get "one"
, "two"
, and "three"
.
Link to reproduction
https://github.com/tobysmith568/nextjs-repro
To Reproduce
Push objects to an array using a for loop in an async function.
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:5 (2 by maintainers)
Oh I missed it. It will be fixed by https://github.com/vercel/next.js/pull/40520
This is a bug in swc.
https://play.swc.rs/?version=1.3.0&code=H4sIAAAAAAAAA11QQQqDMBC8%2B4ohpwTEB1TSQ99Q6KF4aCVWUbJiFCni3xs3RqSXJMzMzsymJOtGdPRpSmi83NeWkAr6iiUBSmYb20%2Bj8%2FRTkDUihRhn4qsejBFFcihnGloWFvmBvQdqjT1AwB8VDZAnc1C1pyjODbPUmcw3k8ykWHbtyk9338IvsQS01pFXecIe3CbrJ1cHCxXyQ6GAL6cZYI2bxGTx2Cz8qmyl8n%2F6xlaeD55esPps%2Fk2p8h9C6eqlXAEAAA%3D%3D&config=H4sIAAAAAAAAAy2LQQ6AIAwE%2F9IzVz3wBx%2FRYDUYUNKWRGL4u9R4252dfeCQAP6BgizElqSdijd4oJBRAsei4IY20IZJqDtQ5J3UFJlg9HytNZGdtRX6%2BGw8yvIvypX6C9UPjkhtAAAA