import{pathToFileURL as u}from"node:url";import{slash as d}from"../../../../utils/path/slash.js";import{logger as o}from"../../../tools/notifiers/logger.js";import{reporter as n}from"../../../tools/notifiers/reporter.js";import{getServerProps as p}from"../../../ssr/server-side-props/get-server-props.js";import{telemetry as f}from"../../../../cli/telemetry/index.js";async function x(r,i){try{n.clearPageRenderProblems();const e=r.getAllRoutes().filter(t=>t.fsPath.match(/\.page\.tsx?$/));if(!e.length)return;const l=o.startTiming();o.info("Validating react pages");const g=await P(r.serverOutDir);for(const t of e){const c=await r.resolveRouteStaticData(t,i),m=await p(t,null,c,r);let a;try{a=(await g(t,m,null,r,f,!0)).error}catch(s){a=s}a&&n.reportPageRenderError({message:a.name==="PageMissingDefaultExportError"?a.message:`Runtime error: ${a.message}`,sourceFileRelativePath:t.fsPath})}o.infoTime(l,`Validated ${e.length} React pages`)}catch(e){await n.panicOnBuild(`Failed to validate react pages: ${e.message}`)}}async function P(r){const e=await import(u(`${d(r)}/index.mjs`)+"?only-exports=true");if(!e.renderPage)throw new Error("renderPage function not found in bundle");return e.renderPage}export{x as validateReactPages};
