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 React channel env missing in custom server #49168

Merged
merged 12 commits into from
May 3, 2023
2 changes: 0 additions & 2 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,6 @@ export default async function build(
const isAppDirEnabled = !!config.experimental.appDir

if (isAppDirEnabled) {
process.env.NEXT_PREBUNDLED_REACT = '1'

if (!process.env.__NEXT_TEST_MODE && ciEnvironment.hasNextSupport) {
const requireHook = require.resolve('../server/require-hook')
const contents = await promises.readFile(requireHook, 'utf8')
Expand Down
13 changes: 11 additions & 2 deletions packages/next/src/server/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,18 @@ export class NextServer {
)
}
}
if (conf.experimental.appDir) {
process.env.NEXT_PREBUNDLED_REACT = '1'

if (this.options.customServer !== false) {
// When running as a custom server with app dir, we must set this env
// to correctly alias the React versions.
if (conf.experimental.appDir) {
process.env.__NEXT_PRIVATE_PREBUNDLED_REACT = conf.experimental
.serverActions
? 'experimental'
: 'next'
}
}

this.server = await this.createServer({
...this.options,
conf,
Expand Down
6 changes: 2 additions & 4 deletions test/e2e/app-dir/navigation/navigation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ createNextDescribe(
{
files: __dirname,
},
({ next, isNextDev, isNextDeploy }) => {
({ next, isNextDeploy }) => {
describe('query string', () => {
it('should set query correctly', async () => {
const browser = await webdriver(next.url, '/')
Expand Down Expand Up @@ -184,9 +184,7 @@ createNextDescribe(
}

expect(stored).toEqual({
// Not actually sure why this is '2' in dev. Possibly something
// related to an update triggered by <HotReload>?
'navigate-https://example.vercel.sh/': isNextDev ? '2' : '1',
'navigate-https://example.vercel.sh/': '1',
'navigation-supported': 'true',
})
})
Expand Down