/** * Runtime preamble — MUST stay the first import in server.ts. * * Next's app-render calls createAsyncLocalStorage(), which falls back to a * throwing FakeAsyncLocalStorage when `globalThis.AsyncLocalStorage` is unset * ("Invariant: AsyncLocalStorage accessed in runtime where it is not * available", error E504). next/dist/server/node-environment-baseline sets it * during Next's own standalone-server bootstrap, but our custom server * (dist/server.js → server-custom.js) can load app-render storage before that * runs. Set it up-front, idempotently, so the invariant can never fire. */ import { AsyncLocalStorage } from 'node:async_hooks'; const g = globalThis as typeof globalThis & { AsyncLocalStorage?: unknown }; g.AsyncLocalStorage ??= AsyncLocalStorage;