next.js
bdbf63ae - fix(next-custom-transforms): never place generated imports before directives (#98717)

Commit
4 days ago
fix(next-custom-transforms): never place generated imports before directives (#98717) ## Summary **What?** Fixes the error reported for a module that has a top-level `"use client"` directive and an inline `"use server"` function directive, e.g. `<form action={async () => { "use server" }} />` in a client page. **Why?** Under Turbopack this reported a bogus error — `The "use client" directive must be placed before other expressions` — even though the directive was already at the top of the file. The actual mistake (an inline server action inside a Client Component) was never surfaced. **How?** On Turbopack's RSC layer the server actions transform runs *before* the React Server Components assert. When it hoists an inline action it prepended its generated imports (`registerServerReference`, action encryption, cache runtime) at index 0 of the module — *above* the `"use client"` directive, which the transform does not consume. The RSC assert then saw an import before the directive and reported it as misplaced. Co-authored-by: vercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
Author
Parents
Loading