Skip to content

Commit

Permalink
Ensure config's experimental field exists (#34500)
Browse files Browse the repository at this point in the history
Fixes #34499 

Starting with `v12.1.0`, you can't use React 18 when you don't use the `experimental` field in the `next.config.js`

![image](https://user-images.githubusercontent.com/29319414/154569017-38f72690-6879-47d1-a0cd-09072af2967c.png)

That's because [this recent change](1aee935) sets `reactRoot` on the user's config without checking if the key already exists:

https://github.com/vercel/next.js/blob/787186a85a054ea870fc964583fe65e9f2286354/packages/next/server/config.ts#L679-L682


This change initializes `experimental` on the `userConfig` if necessary.



## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
  • Loading branch information
bennettdams committed Feb 17, 2022
1 parent 787186a commit 0b95da5
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/next/server/config.ts
Expand Up @@ -678,6 +678,8 @@ export default async function loadConfig(

const hasReactRoot = shouldUseReactRoot()
if (hasReactRoot) {
// users might not have the `experimental` key in their config
userConfig.experimental = userConfig.experimental || {}
userConfig.experimental.reactRoot = true
}

Expand Down

0 comments on commit 0b95da5

Please sign in to comment.