Unverified Commit 743cf685 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Pass nextRuntime in webpack context (#36488)

Follow-up to https://github.com/vercel/next.js/pull/36383 this also exposes the `nextRuntime` for the custom webpack function in `next.config.js` to allow differentiating between the environments. 

x-ref: https://vercel.slack.com/archives/CGU8HUTUH/p1647866770704939
parent 90863c70
......@@ -1820,6 +1820,11 @@ export default async function getBaseWebpackConfig(
defaultLoaders,
totalPages,
webpack,
...(isServer
? {
nextRuntime: isEdgeRuntime ? 'edge' : 'nodejs',
}
: {}),
})
if (!webpackConfig) {
......
......@@ -65,6 +65,8 @@ export interface WebpackConfigContext {
totalPages: number
/** The webpack configuration */
webpack: any
/** The current server runtime */
nextRuntime?: 'nodejs' | 'edge'
}
export interface NextJsWebpackConfig {
......
......@@ -22,6 +22,23 @@ describe('react 18 streaming SSR in minimal mode', () => {
serverComponents: true,
runtime: 'nodejs',
},
webpack(config, { nextRuntime }) {
const path = require('path')
const fs = require('fs')
const runtimeFilePath = path.join(__dirname, 'runtimes.txt')
let runtimeContent = ''
try {
runtimeContent = fs.readFileSync(runtimeFilePath, 'utf8')
runtimeContent += '\n'
} catch (_) {}
runtimeContent += nextRuntime || 'client'
fs.writeFileSync(runtimeFilePath, runtimeContent)
return config
},
},
dependencies: {
react: '18.0.0',
......@@ -34,6 +51,11 @@ describe('react 18 streaming SSR in minimal mode', () => {
next.destroy()
})
it('should pass correct nextRuntime values', async () => {
const content = await next.readFile('runtimes.txt')
expect(content.split('\n').sort()).toEqual(['client', 'edge', 'nodejs'])
})
it('should generate html response by streaming correctly', async () => {
const html = await renderViaHTTP(next.url, '/')
expect(html).toContain('static streaming')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment