Skip to content

Commit

Permalink
fix problem with HMR when middleware and page reference the same node…
Browse files Browse the repository at this point in the history
…_module (vercel#33873)

fixes vercel#31827



## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have 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 helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
  • Loading branch information
sokra authored Feb 1, 2022
1 parent 4786557 commit a803638
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 12 deletions.
12 changes: 0 additions & 12 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -959,11 +959,6 @@ export default async function getBaseWebpackConfig(
},
}

const nonUserCondition = {
include: /node_modules/,
exclude: babelIncludeRegexes,
}

let webpackConfig: webpack.Configuration = {
parallelism: Number(process.env.NEXT_WEBPACK_PARALLELISM) || undefined,
externals: targetWeb
Expand Down Expand Up @@ -1256,13 +1251,6 @@ export default async function getBaseWebpackConfig(
},
],
},
{
...nonUserCondition,
// Make all non-user modules to be compiled in a single layer
// This avoids compiling them mutliple times and avoids module id changes
issuerLayer: 'middleware',
layer: '',
},
...(!config.images.disableStaticImages
? [
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions test/integration/middleware/hmr/pages/about/_middleware.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { NextResponse } from 'next/server'
import magicValue from 'shared-package'

export function middleware(request) {
if (magicValue !== 42) throw new Error('shared-package problem')
return NextResponse.rewrite(new URL('/about/a', request.url))
}
3 changes: 3 additions & 0 deletions test/integration/middleware/hmr/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import magicValue from 'shared-package'
if (magicValue !== 42) throw new Error('shared-package problem')

export default function Home() {
return (
<div>
Expand Down

0 comments on commit a803638

Please sign in to comment.