Skip to content

Commit

Permalink
Fix wrong code condition used when bundling the server (vercel#40987)
Browse files Browse the repository at this point in the history
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: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and BowlingX committed Oct 5, 2022
1 parent f55e062 commit 15b3fc1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/next/build/webpack-config.ts
Expand Up @@ -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'
) {
Expand Down Expand Up @@ -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 + '/')
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/app-dir/app-alias/app/button/page.tsx
@@ -1,5 +1,10 @@
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>
}

0 comments on commit 15b3fc1

Please sign in to comment.