Files
next.js/test/e2e/deferred-entries/next.config.js
Arian Tron 61f56f997c
Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
first commit
2026-03-10 19:37:31 +03:30

107 lines
3.4 KiB
JavaScript

const fs = require('fs')
const path = require('path')
const logFile = path.join(__dirname, '.entry-log')
const callbackLogFile = path.join(__dirname, '.callback-log')
const deferredPageFile = path.join(__dirname, 'app', 'deferred', 'page.tsx')
const routeHandlerFile = path.join(
__dirname,
'app',
'route-handler',
'route.ts'
)
const homePageFile = path.join(__dirname, 'app', 'page.tsx')
let lastHomePageContent = null
/** @type {import('next').NextConfig} */
module.exports = {
experimental: {
deferredEntries: ['/deferred', '/route-handler'],
onBeforeDeferredEntries: async () => {
const timestamp = Date.now()
const homePageContent = fs.readFileSync(homePageFile, 'utf-8')
const shouldWriteDeferredTimestamp =
lastHomePageContent === null || lastHomePageContent !== homePageContent
// Mutate the deferred entry source directly so the deferred build picks
// up callback-time content.
if (shouldWriteDeferredTimestamp) {
const deferredPageContent = fs.readFileSync(deferredPageFile, 'utf-8')
const nextDeferredPageContent = deferredPageContent.replace(
/const CALLBACK_TIMESTAMP = \d+/,
`const CALLBACK_TIMESTAMP = ${timestamp}`
)
if (nextDeferredPageContent === deferredPageContent) {
throw new Error(
'Failed to update CALLBACK_TIMESTAMP in deferred page entry'
)
}
fs.writeFileSync(deferredPageFile, nextDeferredPageContent)
const routeHandlerContent = fs.readFileSync(routeHandlerFile, 'utf-8')
const nextRouteHandlerContent = routeHandlerContent.replace(
/const ROUTE_HANDLER_CALLBACK_TIMESTAMP = \d+/,
`const ROUTE_HANDLER_CALLBACK_TIMESTAMP = ${timestamp}`
)
if (nextRouteHandlerContent === routeHandlerContent) {
throw new Error(
'Failed to update ROUTE_HANDLER_CALLBACK_TIMESTAMP in route handler entry'
)
}
fs.writeFileSync(routeHandlerFile, nextRouteHandlerContent)
// Persist only write-triggering callback timestamps.
// This avoids deferred self-rebuild callback loops in webpack dev.
fs.writeFileSync(callbackLogFile, `callback:${timestamp}\n`)
}
lastHomePageContent = homePageContent
console.log(
`[TEST] onBeforeDeferredEntries callback executed at ${timestamp} (write=${shouldWriteDeferredTimestamp})`
)
// Small delay to ensure we can verify timing
await new Promise((resolve) => setTimeout(resolve, 100))
// Append to entry log to mark callback position in the build sequence
fs.appendFileSync(logFile, `${timestamp}:CALLBACK_EXECUTED\n`)
},
},
// Turbopack loader configuration
turbopack: {
rules: {
'*ts': {
loaders: [
{
loader: path.join(__dirname, 'entry-logger-loader.js'),
},
],
},
'*.tsx': {
loaders: [
{
loader: path.join(__dirname, 'entry-logger-loader.js'),
},
],
},
},
},
// Webpack loader configuration
webpack: (config, { isServer }) => {
// Add the entry logger loader to track when entries are processed
config.module.rules.push({
test: /\.(tsx|ts|js|jsx)$/,
include: [path.join(__dirname, 'app'), path.join(__dirname, 'pages')],
use: [
{
loader: path.join(__dirname, 'entry-logger-loader.js'),
},
],
})
return config
},
}