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
Async function breaks assigning to new objects in for loops #40535
Comments
I think I have the same issue from pushing object literals in an async function, though my code isn't in a for loop. I had a line like myarray.push({ a: await myfunc(), b: 123 }); in an async function and it works in const a = await myfunc();
myarray.push({ a, b: 123 }); const obj = { a: await myfunc(), b: 123 };
myarray.push(obj); |
@magic-akari thanks for the quick fix in swc-project/swc#5861. I would have assumed this should stay open until there's a new patch release of @swc/helpers and next.js is updated to use it. In the meantime other people might come and open more issues here while the bug is still reproducible in next@canary. |
Oh I missed it. |
This updates SWC crates to swc-project/swc@69bf533 --- - Closes vercel#40535 Co-authored-by: JJ Kasper <jj@jjsweb.site>
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
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 innext@canary
as of 14/09/22.See the README in the attached repro for more details.
Expected Behavior
Both the
works
andbroken
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.
The text was updated successfully, but these errors were encountered: