Skip to content

Commit

Permalink
fix(page-static-info): refine warning message to emit once (#65091)
Browse files Browse the repository at this point in the history
### What

- closes #65052 

Emitting warning itself is correct, however

- we emit warning multiple times
- missing additional detail to provide link to the docs

PR fixes those 2.
  • Loading branch information
kwonoj authored and ForsakenHarmony committed Aug 14, 2024
1 parent 928412e commit 5102f61
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ impl CustomTransformer for NextPageStaticInfo {
messages.push(format!("- `export const preferredRegion = {}`", regions));
}

messages.push("Visit https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config for more information.".to_string());

PageStaticInfoIssue {
file_path: ctx.file_path,
messages,
Expand Down
21 changes: 20 additions & 1 deletion packages/next/src/server/dev/turbopack-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,29 @@ export function isWellKnownError(issue: Issue): boolean {
return false
}

const onceErrorSet = new Set()
/**
* Check if given issue is a warning to be display only once.
* This miimics behavior of get-page-static-info's warnOnce.
* @param issue
* @returns
*/
function shouldEmitOnceWarning(issue: Issue): boolean {
const { severity, title } = issue
if (severity === 'warning' && title.value === 'Invalid page configuration') {
if (onceErrorSet.has(issue)) {
return false
}
onceErrorSet.add(issue)
}

return true
}

/// Print out an issue to the console which should not block
/// the build by throwing out or blocking error overlay.
export function printNonFatalIssue(issue: Issue) {
if (isRelevantWarning(issue)) {
if (isRelevantWarning(issue) && shouldEmitOnceWarning(issue)) {
Log.warn(formatIssue(issue))
}
}
Expand Down

0 comments on commit 5102f61

Please sign in to comment.