diff --git a/lib/allNextJsPages.js b/lib/allNextJsPages.js index 4f57d35..30a00df 100644 --- a/lib/allNextJsPages.js +++ b/lib/allNextJsPages.js @@ -60,22 +60,42 @@ const getAllPages = () => { pages.push(new Page({ route, type, filePath, alternativeRoutes })); }); + const renderedDynamicSsgPages = {}; + // Parse SSG pages - Object.entries(staticSsgPages).forEach(([route, { dataRoute }]) => { - pages.push( - new Page({ - route, - type: "ssg", - dataRoute, - alternativeRoutes: route === "/" ? ["/index"] : [], - }) - ); + Object.entries(staticSsgPages).forEach(([route, { srcRoute, dataRoute, initialRevalidateSeconds }]) => { + if (initialRevalidateSeconds && initialRevalidateSeconds != false) { + // Use SSR for SSG pages with revalidate + debugger; + if (renderedDynamicSsgPages[srcRoute]) + return; + + if (srcRoute) { + const dynamicPage = dynamicSsgPages[srcRoute]; + if (dynamicPage) { + dataRoute = dynamicPage.dataRoute; + route = srcRoute; + renderedDynamicSsgPages[route] = true; + } + } + const filePath = join("pages", `${route}.js`); + pages.push(new Page({ route, type: "ssr", filePath, alternativeRoutes: [dataRoute] })); + } else { + pages.push( + new Page({ + route, + type: "ssg", + dataRoute, + alternativeRoutes: route === "/" ? ["/index"] : [], + }) + ); + } }); Object.entries(dynamicSsgPages).forEach( ([route, { dataRoute, fallback }]) => { // Ignore pages without fallback, these are already handled by the // static SSG page block above - if (fallback === false) return; + if (fallback === false || renderedDynamicSsgPages[route]) return; const filePath = join("pages", `${route}.js`); pages.push( diff --git a/tests/fixtures/pages/getStaticProps/dynamic.js b/tests/fixtures/pages/getStaticProps/dynamic.js new file mode 100644 index 0000000..dc26b24 --- /dev/null +++ b/tests/fixtures/pages/getStaticProps/dynamic.js @@ -0,0 +1,32 @@ +import Link from "next/link"; + +const Show = ({ show }) => ( +
This page uses getStaticProps() to pre-fetch a TV show.
+ +{show.name}
+ +This page uses getStaticProps() to pre-fetch a TV show.
+ +{show.name}
+ +