Files
danandGitHub d87f2bd2be Model async userland loading in app routes as a state machine (#95791)
Extracted from https://github.com/vercel/next.js/pull/95468, tries to
address @lubieowoce feedback.

This should be a pure refactor with no publicly observable behavior
changes. We want to simplify the state of how we're loading and tracking
modules, and simplify signatures:

- Extract a state machine into `LazyModule` that hides per-module state.
You can kick it (`loadIfNeeded`), wait for completion with
`waitUntilLoaded`, or peek-or-throw with `assertLoaded`.
- Reading `.userland` while pending now throws with an invariant so we
don't do it accidentally again. Should be unreachable from current
callsites.
- Remove the non-thunk overload from `userland` factory.

Added tests to cover the cases that the refactor had a risk of breaking.
2026-07-15 10:49:07 +01:00

15 lines
457 B
TypeScript

import { nextTestSetup } from 'e2e-utils'
describe('app-route-then-export', () => {
const { next } = nextTestSetup({
files: __dirname,
})
// A module that exports a function named `then` is not an async module,
// even though the exports object is thenable.
it('builds and serves a route handler that exports `then`', async () => {
const res = await next.fetch('/api/thenable')
expect(await res.json()).toEqual({ ok: true })
})
})