Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changepacks/changepack_log_next_partial_css_error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"changes":{"packages/next-plugin/package.json":"Patch"},"note":"Fail a Turbopack build whose CSS the coordinator cannot prove complete, naming the files that never extracted, instead of answering with partial CSS","date":"2026-11-15T00:00:00.000Z"}
150 changes: 73 additions & 77 deletions packages/next-plugin/src/__tests__/coordinator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -851,15 +851,19 @@ describe('coordinator', () => {

try {
// Request CSS with waitForIdle=true but no extractions ever happen
// (totalExtractions === 0), so it should timeout and return CSS anyway
// (totalExtractions === 0): the wait times out and refuses to answer
// with CSS it cannot prove complete.
const res = await httpRequest(
port,
'GET',
'/css?importMainCss=false&waitForIdle=true',
)

expect(res.status).toBe(200)
expect(res.body).toBe('timeout-css')
expect(res.status).toBe(500)
expect(res.body).toBe(
'[devup-ui] coordinator: base CSS is incomplete (not complete after 60000ms); refusing to serve partial CSS.',
)
expect(getCssSpy).not.toHaveBeenCalled()
} finally {
dateNowSpy.mockRestore()
}
Expand Down Expand Up @@ -1469,40 +1473,38 @@ describe('coordinator per-bucket completion', () => {
coordinator.close()
})

// T3: a bucket member that never arrives -> the per-bucket wait fails open
// after maxWaitMs (serves whatever exists) instead of hanging the build.
it('fails open and serves partial CSS when a bucket member never extracts', async () => {
// T3: a bucket member that never arrives -> the per-bucket wait gives up
// after maxWaitMs with an error naming the member, instead of hanging the
// build or serving the chunk without that member's rules.
it('fails the request instead of serving partial CSS when a bucket member never extracts', async () => {
codeExtractSpy.mockReturnValue(extractResult('devup-ui-1.css'))
getCssSpy.mockReturnValue('partial-css')
const warnSpy = spyOn(console, 'warn').mockReturnValue(undefined)
try {
// m1 is a member of the bucket but is never POSTed to /extract.
const canonicalMap = { 'src/m1.tsx': 'src/bucket.tsx' }
const { coordinator, port } = await startAndGetPort(
makeOptions({ canonicalMap, idleThresholdMs: 100, maxWaitMs: 150 }),
)
// Extract only the bucket root; src/m1.tsx stays missing forever.
await extract(port, 'src/bucket.tsx')
// m1 is a member of the bucket but is never POSTed to /extract.
const canonicalMap = { 'src/m1.tsx': 'src/bucket.tsx' }
const { coordinator, port } = await startAndGetPort(
makeOptions({ canonicalMap, idleThresholdMs: 100, maxWaitMs: 150 }),
)
// Extract only the bucket root; src/m1.tsx stays missing forever.
await extract(port, 'src/bucket.tsx')
getCssSpy.mockClear()

const t0 = Date.now()
const res = await httpRequest(
port,
'GET',
'/css?fileNum=1&importMainCss=true&waitForIdle=true',
)
const elapsed = Date.now() - t0
const t0 = Date.now()
const res = await httpRequest(
port,
'GET',
'/css?fileNum=1&importMainCss=true&waitForIdle=true',
)
const elapsed = Date.now() - t0

// Resolves via the hard timeout (fail open) rather than hanging.
expect(res.status).toBe(200)
expect(res.body).toBe('partial-css')
expect(elapsed).toBeGreaterThanOrEqual(150)
expect(warnSpy).toHaveBeenCalled()
expect(getCssSpy).toHaveBeenCalledWith(1, true)
// Resolves via the hard timeout rather than hanging, and says why.
expect(res.status).toBe(500)
expect(res.body).toBe(
'[devup-ui] coordinator: bucket "src/bucket.tsx" is incomplete (not complete after 150ms); refusing to serve partial CSS. Files not extracted: src/m1.tsx.',
)
expect(elapsed).toBeGreaterThanOrEqual(150)
expect(getCssSpy).not.toHaveBeenCalled()

coordinator.close()
} finally {
warnSpy.mockRestore()
}
coordinator.close()
})

// T4: base css resolves DETERMINISTICALLY once every route-reachable runtime
Expand Down Expand Up @@ -1636,49 +1638,39 @@ describe('coordinator per-bucket completion', () => {
coordinator.close()
})

// T7: legacy callers that do not prewarm still fail open after the quiet
// window when a graph member never reports, rather than hanging forever.
// Production plugin builds take the deterministic prewarmed path instead.
it('serves a bucket via the quiet exit when a member is never compiled', async () => {
// T7: when a known member never reports and extraction goes quiet, the wait
// gives up early with an error naming it. Production plugin builds take the
// deterministic prewarmed path instead and never get here.
it('fails a bucket after the quiet window when a member is never compiled', async () => {
codeExtractSpy.mockReturnValue(extractResult('devup-ui-1.css'))
getCssSpy.mockReturnValue('bucket-css')
const infoSpy = spyOn(console, 'info').mockReturnValue(undefined)
try {
const warnSpy = spyOn(console, 'warn').mockReturnValue(undefined)
try {
const canonicalMap = { 'src/phantom.tsx': 'src/bucket.tsx' }
const { coordinator, port } = await startAndGetPort(
makeOptions({ canonicalMap, quietMs: 100, maxWaitMs: 10_000 }),
)
await extract(port, 'src/bucket.tsx')
const canonicalMap = { 'src/phantom.tsx': 'src/bucket.tsx' }
const { coordinator, port } = await startAndGetPort(
makeOptions({ canonicalMap, quietMs: 100, maxWaitMs: 10_000 }),
)
await extract(port, 'src/bucket.tsx')

const t0 = Date.now()
const res = await httpRequest(
port,
'GET',
'/css?fileNum=1&importMainCss=true&waitForIdle=true',
)
const elapsed = Date.now() - t0

expect(res.status).toBe(200)
expect(res.body).toBe('bucket-css')
// Resolved by the quiet exit (~100ms), NOT the 10s wall-clock backstop.
expect(elapsed).toBeLessThan(5000)
expect(infoSpy).toHaveBeenCalled()
expect(warnSpy).not.toHaveBeenCalled()

coordinator.close()
} finally {
warnSpy.mockRestore()
}
} finally {
infoSpy.mockRestore()
}
const t0 = Date.now()
const res = await httpRequest(
port,
'GET',
'/css?fileNum=1&importMainCss=true&waitForIdle=true',
)
const elapsed = Date.now() - t0

expect(res.status).toBe(500)
expect(res.body).toBe(
'[devup-ui] coordinator: bucket "src/bucket.tsx" is incomplete (no extraction for 100ms); refusing to serve partial CSS. Files not extracted: src/phantom.tsx.',
)
// Ended by the quiet window (~100ms), NOT the 10s wall-clock backstop.
expect(elapsed).toBeLessThan(5000)

coordinator.close()
})

// T8: the same legacy quiet fallback applies to an expected base file when
// the caller did not seed prewarmed completion state.
it('serves base css via the quiet exit when an expectedBaseFile is never compiled', async () => {
// T8: the same quiet window ends a base wait whose expected file never
// reports when the caller did not seed prewarmed completion state.
it('fails base css after the quiet window when an expectedBaseFile is never compiled', async () => {
codeExtractSpy.mockReturnValue(extractResult('devup-ui.css'))
getCssSpy.mockReturnValue('base-css')
const { coordinator, port } = await startAndGetPort(
Expand All @@ -1698,17 +1690,19 @@ describe('coordinator per-bucket completion', () => {
)
const elapsed = Date.now() - t0

expect(res.status).toBe(200)
expect(res.body).toBe('base-css')
expect(res.status).toBe(500)
expect(res.body).toBe(
'[devup-ui] coordinator: base CSS is incomplete (no extraction for 100ms); refusing to serve partial CSS. Files not extracted: src/phantom.tsx.',
)
// Quiet exit (~100ms), not the 10s backstop.
expect(elapsed).toBeLessThan(5000)

coordinator.close()
})

// T6: a phantom expectedBaseFile that never extracts fails open via the
// dormant maxWaitMs backstop instead of hanging the build forever.
it('fails open on a phantom expectedBaseFile via maxWaitMs', async () => {
// T6: a phantom expectedBaseFile that never extracts ends the wait via the
// dormant maxWaitMs backstop with an error instead of hanging the build.
it('fails a phantom expectedBaseFile via maxWaitMs', async () => {
codeExtractSpy.mockReturnValue(extractResult('devup-ui.css'))
getCssSpy.mockReturnValue('base-css')
const { coordinator, port } = await startAndGetPort(
Expand All @@ -1727,8 +1721,10 @@ describe('coordinator per-bucket completion', () => {
)
const elapsed = Date.now() - t0

expect(res.status).toBe(200)
expect(res.body).toBe('base-css')
expect(res.status).toBe(500)
expect(res.body).toBe(
'[devup-ui] coordinator: base CSS is incomplete (not complete after 150ms); refusing to serve partial CSS. Files not extracted: src/phantom.tsx.',
)
expect(elapsed).toBeGreaterThanOrEqual(150)

coordinator.close()
Expand Down
37 changes: 36 additions & 1 deletion packages/next-plugin/src/__tests__/css-loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,42 @@ describe('devupUICssLoader', () => {
} as unknown as CssLoaderThis)(Buffer.from(''), '', '')
})

expect(error.message).toBe('Coordinator CSS error: 500')
expect(error.message).toBe(
'Coordinator CSS error: 500: Internal Server Error',
)
server.close()
})

it('should error with only the status when the coordinator sends no reason', async () => {
const server = http.createServer((_req, res) => {
res.writeHead(503)
res.end()
})
await new Promise<void>((resolve) => server.listen(0, '127.0.0.1', resolve))
const port = (server.address() as { port: number }).port
const portFile = `test-coordinator-empty-err-${port}.port`

existsSyncSpy.mockImplementation((p: unknown) => p === portFile)
readFileSyncSpy.mockImplementation((p: unknown) =>
p === portFile ? String(port) : '{}',
)

const error = await new Promise<Error>((resolve) => {
const asyncCallback = mock((err: Error | null) => {
if (err) resolve(err)
})
devupUICssLoader.bind({
async: () => asyncCallback,
addContextDependency: mock(),
getOptions: () => ({
...defaultOptions,
coordinatorPortFile: portFile,
}),
resourcePath: 'devup-ui.css',
} as unknown as CssLoaderThis)(Buffer.from(''), '', '')
})

expect(error.message).toBe('Coordinator CSS error: 503')
server.close()
})

Expand Down
Loading
Loading