Unverified Commit daad1171 authored by Shu Ding's avatar Shu Ding Committed by GitHub

Fix wrong code condition used when bundling the server (#40987)

We observed this bug when using `.tsx` as the extension (currently the
condition only matches `.m?js`). Besides that, `react/jsx-runtime`
shouldn't be external too because it has React imported.

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
Co-authored-by: 's avatarkodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
parent e8f85e3d
......@@ -1000,6 +1000,7 @@ export default async function getBaseWebpackConfig(
if (layer === WEBPACK_LAYERS.server) {
if (
request === 'react' ||
request === 'react/jsx-runtime' ||
request ===
'next/dist/compiled/react-server-dom-webpack/writer.browser.server'
) {
......@@ -1504,7 +1505,7 @@ export default async function getBaseWebpackConfig(
issuerLayer: WEBPACK_LAYERS.server,
test: (req: string) => {
if (
!/\.m?js/.test(req) ||
!codeCondition.test.test(req) ||
config.experimental.optoutServerComponentsBundle?.some(
(mod) => {
return req.includes('/node_modules/' + mod + '/')
......
import Button from '@/ui/button'
import React from 'react'
export default function page() {
if ('useState' in React) {
throw new Error('React is not resolved correctly.')
}
return <Button>click</Button>
}
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