next.js
59a747c4 - Error on directives in positions where they are silently ignored

Commit
24 days ago
Error on directives in positions where they are silently ignored A "use client" directive inside a function body was previously ignored silently. Add a read-only pre-scan to the server actions transform (which runs for app router code in both Turbopack and webpack) that reports: - "use client" anywhere inside a function body (functions, arrows, methods, accessors, constructors): it is only valid at the top of a module. - "use client"/"use server"/"use cache" inside nested statement containers (blocks, if/else branches, loops, try/catch, switch cases, labels), where they can never take effect. Valid usage is unchanged: top-of-file directives, function-top inline server actions and cache functions, directive-shaped strings used as values, and pages router files (the transform does not run there). Co-authored-by: Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com>
Parents
Loading