Skip to content

Commit

Permalink
Fix required files matching in rsc (vercel#34137)
Browse files Browse the repository at this point in the history
Fix the wrong filename evaluation of `MIDDLEWARE_FLIGHT_MANIFEST` in required files. Besides checking the generated files, check if they're declared correctly in `required-server-files.json`
  • Loading branch information
huozhi authored Feb 9, 2022
1 parent 28f65ff commit 52c3d07
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
5 changes: 2 additions & 3 deletions packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,8 @@ export default async function build(
hasServerComponents
? path.join(
SERVER_DIRECTORY,
MIDDLEWARE_FLIGHT_MANIFEST + runtime === 'edge'
? '.js'
: '.json'
MIDDLEWARE_FLIGHT_MANIFEST +
(runtime === 'edge' ? '.js' : '.json')
)
: null,
REACT_LOADABLE_MANIFEST,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,25 @@ describe('Edge runtime - prod', () => {

it('should generate middleware SSR manifests for edge runtime', async () => {
const distServerDir = join(distDir, 'server')
const hasFile = (filename) => fs.existsSync(join(distServerDir, filename))

const files = [
'middleware-build-manifest.js',
'middleware-flight-manifest.js',
'middleware-ssr-runtime.js',
'middleware-manifest.json',
]

const requiredServerFiles = (
await fs.readJSON(join(distDir, 'required-server-files.json'))
).files

files.forEach((file) => {
expect(hasFile(file)).toBe(true)
const filepath = join(distServerDir, file)
expect(fs.existsSync(filepath)).toBe(true)
})

requiredServerFiles.forEach((file) => {
const requiredFilePath = join(appDir, file)
expect(fs.existsSync(requiredFilePath)).toBe(true)
})
})

Expand Down Expand Up @@ -250,17 +259,25 @@ const nodejsRuntimeBasicSuite = {
if (env === 'prod') {
it('should generate middleware SSR manifests for Node.js', async () => {
const distServerDir = join(distDir, 'server')
const hasFile = (filename) =>
fs.existsSync(join(distServerDir, filename))

const requiredServerFiles = (
await fs.readJSON(join(distDir, 'required-server-files.json'))
).files

const files = [
'middleware-build-manifest.js',
'middleware-flight-manifest.json',
'middleware-manifest.json',
]

files.forEach((file) => {
if (!hasFile(file)) console.log(file)
expect(hasFile(file)).toBe(true)
const filepath = join(distServerDir, file)
expect(fs.existsSync(filepath)).toBe(true)
})

requiredServerFiles.forEach((file) => {
const requiredFilePath = join(appDir, file)
expect(fs.existsSync(requiredFilePath)).toBe(true)
})
})
}
Expand Down

0 comments on commit 52c3d07

Please sign in to comment.