Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix not-found case with incremental tracing #70041

Merged
merged 3 commits into from
Sep 12, 2024
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
11 changes: 9 additions & 2 deletions packages/next/src/build/flying-shuttle/detect-changed-entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,10 @@ export async function detectChangedEntries({
console.error('missing trace data', traceFile, normalizedEntry)
}
} catch (err) {
console.error(`Failed to detect change for ${entry}`, err)
console.error(
`Failed to detect change for ${entry} ${normalizedEntry}`,
err
)
}
}

Expand Down Expand Up @@ -275,7 +278,11 @@ export async function detectChangedEntries({
}

for (const entry of appPaths || []) {
const normalizedEntry = getPageFromPath(entry, pageExtensions)
let normalizedEntry = getPageFromPath(entry, pageExtensions)

if (normalizedEntry === '/not-found') {
normalizedEntry = '/_not-found/page'
}
await detectChange({ entry, normalizedEntry, type: 'app' })
}

Expand Down
5 changes: 3 additions & 2 deletions packages/next/src/build/flying-shuttle/stitch-builds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,16 @@ export async function stitchBuilds(
if (normalizedEntry === '/') {
normalizedEntry = '/index'
}
if (normalizedEntry === '/not-found') {
normalizedEntry = '/_not-found/page'
}
await copyPageChunk(normalizedEntry, type)
} finally {
copySema.release()
}
})
)
}
// always attempt copying not-found chunk
await copyPageChunk('/_not-found/page', 'app').catch(() => {})

// merge dynamic/static routes in routes-manifest
const [restoreRoutesManifest, currentRoutesManifest] = await Promise.all(
Expand Down
9 changes: 9 additions & 0 deletions test/e2e/app-dir/app/app/not-found.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as styles from './not-found.module.css'

export default function Page() {
return (
<>
<p className={styles.text}>This page could not be found</p>
</>
)
}
3 changes: 3 additions & 0 deletions test/e2e/app-dir/app/app/not-found.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.text {
color: cyan;
}
75 changes: 65 additions & 10 deletions test/e2e/app-dir/app/flying-shuttle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ import { nextTestSetup, isNextStart } from 'e2e-utils'
initialConfig = manifest.config
})

function checkErrorLogs() {
expect(next.cliOutput).not.toContain('ENOENT')
expect(next.cliOutput).not.toContain('Failed to detect change')
}

async function checkShuttleManifest() {
const manifest = await next.readJSON(
'.next/cache/shuttle/shuttle-manifest.json'
Expand All @@ -48,6 +53,14 @@ import { nextTestSetup, isNextStart } from 'e2e-utils'
})
}

async function nextStart() {
// our initial build was built in store-only mode so
// enable full version in successive builds
delete next.env['NEXT_PRIVATE_FLYING_SHUTTLE_STORE_ONLY']
next.env['NEXT_PRIVATE_FLYING_SHUTTLE'] = '1'
await next.start()
}

it('should have file hashes in trace files', async () => {
const deploymentsTracePath =
'.next/server/app/dashboard/deployments/[id]/page.js.nft.json'
Expand Down Expand Up @@ -199,14 +212,20 @@ import { nextTestSetup, isNextStart } from 'e2e-utils'
content: 'hello from app/dashboard/deployments/[id]',
type: 'app',
},
{
path: '/non-existent/path',
content: 'This page could not be found',
type: 'app',
status: 404,
},
]

for (const testPath of testPaths) {
const { path, content } = testPath
const { path, content, status } = testPath
require('console').error('checking', path)

const res = await next.fetch(path)
expect(res.status).toBe(200)
expect(res.status).toBe(status || 200)

const browser = await next.browser(path)

Expand Down Expand Up @@ -252,20 +271,17 @@ import { nextTestSetup, isNextStart } from 'e2e-utils'
}

it('should only rebuild just a changed app route correctly', async () => {
// our initial build was built in store-only mode so
// enable full version in successive builds
delete next.env['NEXT_PRIVATE_FLYING_SHUTTLE_STORE_ONLY']
next.env['NEXT_PRIVATE_FLYING_SHUTTLE'] = '1'

await next.stop()

const dataPath = 'app/dashboard/deployments/[id]/data.json'
const originalContent = await next.readFile(dataPath)

try {
await next.patchFile(dataPath, JSON.stringify({ hello: 'again' }))
await next.start()
await nextStart()
checkErrorLogs()

expect(next.cliOutput).not.toContain('/not-found')
expect(next.cliOutput).not.toContain('/catch-all')
expect(next.cliOutput).not.toContain('/blog/[slug]')
expect(next.cliOutput).toContain('/dashboard/deployments/[id]')
Expand All @@ -291,9 +307,12 @@ import { nextTestSetup, isNextStart } from 'e2e-utils'
'hello from pages/index!!'
)
)
await next.start()
await nextStart()

checkErrorLogs()

expect(next.cliOutput).toContain('/')
expect(next.cliOutput).not.toContain('/not-found')
expect(next.cliOutput).not.toContain('/catch-all')
expect(next.cliOutput).not.toContain('/blog/[slug]')

Expand Down Expand Up @@ -321,10 +340,13 @@ import { nextTestSetup, isNextStart } from 'e2e-utils'
)
)
await next.patchFile(dataPath, JSON.stringify({ hello: 'again' }))
await next.start()
await nextStart()

checkErrorLogs()

expect(next.cliOutput).toContain('/')
expect(next.cliOutput).toContain('/dashboard/deployments/[id]')
expect(next.cliOutput).not.toContain('/not-found')
expect(next.cliOutput).not.toContain('/catch-all')
expect(next.cliOutput).not.toContain('/blog/[slug]')

Expand All @@ -335,5 +357,38 @@ import { nextTestSetup, isNextStart } from 'e2e-utils'
await next.patchFile(dataPath, originalDataContent)
}
})

it('should rebuild not-found when it changed', async () => {
await next.stop()

const dataPath = 'app/not-found.module.css'
const originalDataContent = await next.readFile(dataPath)

try {
await next.patchFile(
dataPath,
originalDataContent.replace('cyan', 'pink')
)
await nextStart()

checkErrorLogs()

expect(next.cliOutput).toContain('/not-found')

const browser = await next.browser('/non-existent/path')
await retry(async () => {
expect(
await browser.eval(
'getComputedStyle(document.querySelector("p")).color'
)
).toBe('rgb(255, 192, 203)')
})

await checkShuttleManifest()
await checkAppPagesNavigation()
} finally {
await next.patchFile(dataPath, originalDataContent)
}
})
}
)
Loading