Unverified Commit fa9f684e authored by OJ Kwon's avatar OJ Kwon Committed by GitHub

fix(page-static-info): refine warning message to emit once (#65091)

### 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.
parent f64db555
...@@ -100,6 +100,8 @@ impl CustomTransformer for NextPageStaticInfo { ...@@ -100,6 +100,8 @@ impl CustomTransformer for NextPageStaticInfo {
messages.push(format!("- `export const preferredRegion = {}`", regions)); 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 { PageStaticInfoIssue {
file_path: ctx.file_path, file_path: ctx.file_path,
messages, messages,
......
...@@ -62,10 +62,29 @@ export function isWellKnownError(issue: Issue): boolean { ...@@ -62,10 +62,29 @@ export function isWellKnownError(issue: Issue): boolean {
return false 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 /// Print out an issue to the console which should not block
/// the build by throwing out or blocking error overlay. /// the build by throwing out or blocking error overlay.
export function printNonFatalIssue(issue: Issue) { export function printNonFatalIssue(issue: Issue) {
if (isRelevantWarning(issue)) { if (isRelevantWarning(issue) && shouldEmitOnceWarning(issue)) {
Log.warn(formatIssue(issue)) Log.warn(formatIssue(issue))
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment