Skip to content

Commit

Permalink
Rename currentIssues to currentEntryIssues (#62524)
Browse files Browse the repository at this point in the history
## What?

Renaming this as a follow-up PR is going to introduce top-level errors.

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->


Closes NEXT-2589
  • Loading branch information
timneutkens authored Feb 26, 2024
1 parent 222a773 commit 4ebeace
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 54 deletions.
16 changes: 8 additions & 8 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ import { isInterceptionRouteAppPath } from '../server/future/helpers/interceptio
import {
getTurbopackJsConfig,
handleEntrypoints,
type IssuesMap,
type EntryIssuesMap,
handleRouteType,
handlePagesErrorRoute,
formatIssue,
Expand Down Expand Up @@ -1390,7 +1390,7 @@ export default async function build(
page: new Map(),
}

const currentIssues: IssuesMap = new Map()
const currentEntryIssues: EntryIssuesMap = new Map()

const manifestLoader = new TurbopackManifestLoader({ buildId, distDir })

Expand All @@ -1412,7 +1412,7 @@ export default async function build(
await handleEntrypoints({
entrypoints,
currentEntrypoints,
currentIssues,
currentEntryIssues,
manifestLoader,
nextConfig: config,
rewrites: emptyRewritesObjToBeImplemented,
Expand Down Expand Up @@ -1446,7 +1446,7 @@ export default async function build(
pathname: page,
route,

currentIssues,
currentEntryIssues,
entrypoints: currentEntrypoints,
manifestLoader,
rewrites: emptyRewritesObjToBeImplemented,
Expand All @@ -1461,7 +1461,7 @@ export default async function build(
dev: false,
pathname: normalizeAppPath(page),
route,
currentIssues,
currentEntryIssues,
entrypoints: currentEntrypoints,
manifestLoader,
rewrites: emptyRewritesObjToBeImplemented,
Expand All @@ -1471,7 +1471,7 @@ export default async function build(

enqueue(() =>
handlePagesErrorRoute({
currentIssues,
currentEntryIssues,
entrypoints: currentEntrypoints,
manifestLoader,
rewrites: emptyRewritesObjToBeImplemented,
Expand All @@ -1488,8 +1488,8 @@ export default async function build(
page: string
message: string
}[] = []
for (const [page, pageIssues] of currentIssues) {
for (const issue of pageIssues.values()) {
for (const [page, entryIssues] of currentEntryIssues) {
for (const issue of entryIssues.values()) {
errors.push({
page,
message: formatIssue(issue),
Expand Down
47 changes: 24 additions & 23 deletions packages/next/src/server/dev/hot-reloader-turbopack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import { trace } from '../../trace'
import type { VersionInfo } from './parse-version-info'
import {
type ChangeSubscriptions,
type IssuesMap,
type EntryIssuesMap,
formatIssue,
getTurbopackJsConfig,
handleEntrypoints,
Expand Down Expand Up @@ -151,7 +151,7 @@ export async function createHotReloaderTurbopack(
app: new Map(),
}

const currentIssues: IssuesMap = new Map()
const currentEntryIssues: EntryIssuesMap = new Map()

const manifestLoader = new TurbopackManifestLoader({ buildId, distDir })

Expand Down Expand Up @@ -253,7 +253,7 @@ export async function createHotReloaderTurbopack(
let hmrEventHappened = false
let hmrHash = 0
const sendEnqueuedMessages = () => {
for (const [, issueMap] of currentIssues) {
for (const [, issueMap] of currentEntryIssues) {
if (issueMap.size > 0) {
// During compilation errors we want to delay the HMR events until errors are fixed
return
Expand Down Expand Up @@ -307,7 +307,7 @@ export async function createHotReloaderTurbopack(
}

type ClientState = {
clientIssues: IssuesMap
clientIssues: EntryIssuesMap
hmrPayloads: Map<string, HMR_ACTION_TYPES>
turbopackUpdates: TurbopackUpdate[]
subscriptions: Map<string, AsyncIterator<any>>
Expand All @@ -333,7 +333,7 @@ export async function createHotReloaderTurbopack(
const changed = await changedPromise

for await (const change of changed) {
processIssues(currentIssues, key, change)
processIssues(currentEntryIssues, key, change)
const payload = await makePayload(change)
if (payload) {
sendHmr(key, payload)
Expand All @@ -347,7 +347,7 @@ export async function createHotReloaderTurbopack(
await subscription.return?.()
changeSubscriptions.delete(key)
}
currentIssues.delete(key)
currentEntryIssues.delete(key)
}

async function subscribeToHmrEvents(client: ws, id: string) {
Expand Down Expand Up @@ -409,7 +409,7 @@ export async function createHotReloaderTurbopack(
currentEntrypoints,

changeSubscriptions,
currentIssues,
currentEntryIssues: currentEntryIssues,
manifestLoader,
nextConfig: opts.nextConfig,
rewrites: opts.fsChecker.rewrites,
Expand Down Expand Up @@ -486,7 +486,7 @@ export async function createHotReloaderTurbopack(
// TODO: Figure out if socket type can match the NextJsHotReloaderInterface
onHMR(req, socket: Socket, head) {
wsServer.handleUpgrade(req, socket, head, (client) => {
const clientIssues: IssuesMap = new Map()
const clientIssues: EntryIssuesMap = new Map()
const subscriptions: Map<string, AsyncIterator<any>> = new Map()

clients.add(client)
Expand Down Expand Up @@ -582,15 +582,15 @@ export async function createHotReloaderTurbopack(
client.send(JSON.stringify(turbopackConnected))

const errors: CompilationError[] = []
const addIssues = (pageIssues: Map<string, Issue>) => {
for (const issue of pageIssues.values()) {
const addIssues = (entryIssues: Map<string, Issue>) => {
for (const issue of entryIssues.values()) {
errors.push({
message: formatIssue(issue),
})
}
}
clientIssues.forEach(addIssues)
currentIssues.forEach(addIssues)
currentEntryIssues.forEach(addIssues)

const sync: SyncAction = {
action: HMR_ACTIONS_SENT_TO_BROWSER.SYNC,
Expand Down Expand Up @@ -622,22 +622,23 @@ export async function createHotReloaderTurbopack(
// Not implemented yet.
},
async getCompilationErrors(page) {
const appKey = getEntryKey('app', 'server', page)
const pagesKey = getEntryKey('pages', 'server', page)
const appEntryKey = getEntryKey('app', 'server', page)
const pagesEntryKey = getEntryKey('pages', 'server', page)

const thisPageIssues =
currentIssues.get(appKey) ?? currentIssues.get(pagesKey)
if (thisPageIssues !== undefined && thisPageIssues.size > 0) {
const thisEntryIssues =
currentEntryIssues.get(appEntryKey) ??
currentEntryIssues.get(pagesEntryKey)
if (thisEntryIssues !== undefined && thisEntryIssues.size > 0) {
// If there is an error related to the requesting page we display it instead of the first error
return [...thisPageIssues.values()].map(
return [...thisEntryIssues.values()].map(
(issue) => new Error(formatIssue(issue))
)
}

// Otherwise, return all errors across pages
const errors = []
for (const pageIssues of currentIssues.values()) {
for (const issue of pageIssues.values()) {
for (const entryIssues of currentEntryIssues.values()) {
for (const issue of entryIssues.values()) {
errors.push(new Error(formatIssue(issue)))
}
}
Expand Down Expand Up @@ -687,7 +688,7 @@ export async function createHotReloaderTurbopack(
let finishBuilding = startBuilding(pathname, requestUrl, false)
try {
await handlePagesErrorRoute({
currentIssues,
currentEntryIssues,
entrypoints: currentEntrypoints,
manifestLoader,
rewrites: opts.fsChecker.rewrites,
Expand Down Expand Up @@ -737,7 +738,7 @@ export async function createHotReloaderTurbopack(
page,
pathname,
route,
currentIssues,
currentEntryIssues: currentEntryIssues,
entrypoints: currentEntrypoints,
manifestLoader,
readyIds,
Expand Down Expand Up @@ -781,7 +782,7 @@ export async function createHotReloaderTurbopack(
const errors = new Map<string, CompilationError>()
const addErrors = (
errorsMap: Map<string, CompilationError>,
issues: IssuesMap
issues: EntryIssuesMap
) => {
for (const issueMap of issues.values()) {
for (const [key, issue] of issueMap) {
Expand All @@ -798,7 +799,7 @@ export async function createHotReloaderTurbopack(
}
}
}
addErrors(errors, currentIssues)
addErrors(errors, currentEntryIssues)

for (const client of clients) {
const state = clientStates.get(client)
Expand Down
Loading

0 comments on commit 4ebeace

Please sign in to comment.