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

18 lines
545 B
TypeScript

import { nextTestSetup } from 'e2e-utils'
describe('app-route-async-module-error', () => {
const { next } = nextTestSetup({
files: __dirname,
skipStart: true,
})
// The route module uses top-level await, so the error rejects the module
// promise instead of throwing during require(). It must still fail the
// build.
it('fails the build when an async route module rejects', async () => {
const { exitCode, cliOutput } = await next.build()
expect(cliOutput).toContain('Kaboom')
expect(exitCode).toBe(1)
})
})