Skip to content

Commit

Permalink
Fix React channel env missing in custom server (#49168)
Browse files Browse the repository at this point in the history
Fixes #48948
([repro](#48948 (comment))).
When running inside a custom server with app dir, we should always opt
into the prebundled React with correct channels.

Thanks @karlhorky for help testing it!

Fixes #49169 too.

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
shuding and kodiakhq[bot] committed May 3, 2023
1 parent 39654fd commit 248f2de
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
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

0 comments on commit 248f2de

Please sign in to comment.