AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Turbopack Production Build Eliminates Side Effects Of Pure-Annotated IIFE-Returned Function

Next.js 16.3.1 with Turbopack minifier incorrectly removes the invocation of a function returned by a `/* @__PURE__ */`-annotated self-invoking function expression (IIFE). The minifier extends the pure annotation's scope to the subsequent call of the returned function, eliminating necessary side effects such as `requestAnimationFrame` scheduling and callback execution. This causes production-only regressions in applications using patterns emitted by esbuild/tsup keepNames, notably affecting `@radix-ui/react-scroll-area`.

highConfidence 92%Next.jsAffected V16.3.1

Origin Analysis

The Turbopack/SWC minifier treats the result of a call expression annotated with `/* @__PURE__ */` as side-effect-free and propagates this assumption to any later call of that result. In this pattern, the outer IIFE is marked pure, but the returned function (assigned to a variable and then invoked separately) has observable side effects. The minifier incorrectly considers the invocation of the returned function to be pure and removes it entirely.
1. Create a Next.js 16.3.1 project with Turbopack enabled by default. 2. Use a `/* @__PURE__ */`-annotated IIFE that returns a named function via a name-preserving helper (e.g., `__name`). Call that returned function inside a `useEffect` with side effects (e.g., starting a `requestAnimationFrame` loop). 3. Run `npm run build && npm run start`. Observe that the side effects never occur (e.g., counter stays at 0). 4. Run `npm run dev` and observe that side effects work correctly. 5. Inspect the production chunk to see the call to the returned function compiled away to a no-op.

Fixing Code Block

Edge Case Audit

This workaround may slightly reduce tree-shaking effectiveness for the affected code, potentially increasing bundle size. It does not address the underlying minifier bug and may need to be reapplied after updates to the affected package or Next.js. If applying to `node_modules`, the patch will be lost on reinstall; use a persistent patch mechanism (e.g., `patch-package`). Rollback is straightforward: restore the original annotations. Official fix should be implemented in Turbopack's minifier to correctly limit the scope of pure annotations.

Ecosystem Topology