You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
…74179)
In #73059 we added build-time checks for the forbidden usage of `this`
and `arguments` in server functions. A nested function expression is
however allowed to use these expressions.
fixes#74181
To add a bit more context: `this` is forbidden in server actions because
the Next.js compiler hoists inline server actions out of their original
location into the module scope, so that they can be imported and invoked
by the action handler. Due to this hoisting, the `this` context gets
lost and is not available to the server action.
To prevent surprising runtime errors for such cases, we emit a build
error to provide feedback to developers as early as possible.
However, nested function declarations or function expressions create a
new `this` context, and in those it's allowed to access `this` and
`arguments`.
For consistency, and to prevent surprises when refactoring server
actions, we apply the same rules for module-level server actions.
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.
Link to the code that reproduces this issue
https://github.com/maciej-ka/next-server-action-valid-this
To Reproduce
npm run dev
Current vs. Expected behavior
Current
Expected
Provide environment information
Which area(s) are affected? (Select all that apply)
Not sure
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local), next start (local), Vercel (Deployed), Other (Deployed)
Additional context
Debug
When debugging on Next.js version before forbidding
this
(available on branch of reproduction repo)
Results are
Motivation
While the first case could be forbidden,
second case, where
this
is aStatement
should be allowed.Links
Forbidden
this
introduced in: #73059Ticket created from discussion: #74124
Solution PR by changing a function visitor: #74179
The text was updated successfully, but these errors were encountered: