Skip to content

Commit

Permalink
Refactor code (#43828)
Browse files Browse the repository at this point in the history
Didn't modify any test, just merging HMR related ones together.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/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`
- [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) 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`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
  • Loading branch information
shuding committed Dec 8, 2022
1 parent 579979d commit 8da43b1
Show file tree
Hide file tree
Showing 2 changed files with 194 additions and 191 deletions.
14 changes: 8 additions & 6 deletions packages/next/server/dev/hot-reloader.ts
Expand Up @@ -766,7 +766,7 @@ export default class HotReloader {
(
pageHashMap: Map<string, string>,
changedItems: Set<string>,
serverComponentChangeCallback?: (key: string) => void
serverComponentChangedItems?: Set<string>
) =>
(stats: webpack.Compilation) => {
try {
Expand Down Expand Up @@ -849,12 +849,12 @@ export default class HotReloader {
}
pageHashMap.set(key, curHash)

if (serverComponentChangeCallback) {
if (serverComponentChangedItems) {
const serverKey = WEBPACK_LAYERS.server + ':' + key
const prevServerHash = pageHashMap.get(serverKey)
const curServerHash = chunksHashServerLayer.toString()
if (prevServerHash && prevServerHash !== curServerHash) {
serverComponentChangeCallback(key)
serverComponentChangedItems.add(key)
}
pageHashMap.set(serverKey, curServerHash)
}
Expand All @@ -877,16 +877,18 @@ export default class HotReloader {
)
this.multiCompiler.compilers[1].hooks.emit.tap(
'NextjsHotReloaderForServer',
trackPageChanges(prevServerPageHashes, changedServerPages, (key) =>
changedServerComponentPages.add(key)
trackPageChanges(
prevServerPageHashes,
changedServerPages,
changedServerComponentPages
)
)
this.multiCompiler.compilers[2].hooks.emit.tap(
'NextjsHotReloaderForServer',
trackPageChanges(
prevEdgeServerPageHashes,
changedEdgeServerPages,
(key) => changedServerComponentPages.add(key)
changedServerComponentPages
)
)

Expand Down

0 comments on commit 8da43b1

Please sign in to comment.