diff --git a/demos/default/pages/index.js b/demos/default/pages/index.js index 555a7f7965..bbc32e45bf 100644 --- a/demos/default/pages/index.js +++ b/demos/default/pages/index.js @@ -17,13 +17,14 @@ const Index = ({ shows, nodeEnv }) => {
-

This is a demo of a NextJS application with Server-Side Rendering (SSR).

+

This is a demo of a NextJS application with Incremental Static Regeneration (ISR).

-

Server-Side Rendering

+

Incremental Static Regeneration

- This page is server-side rendered. It fetches a random list of five TV shows from the TVmaze REST API. Refresh - this page to see it change. + This page is rendered by an On-Demand Builder (ODB) function. It fetches a random list of five TV shows from + the TVmaze REST API. After 60 seconds, the ODB cache is invalidated and the page will be re-rendered on the + next request.

NODE_ENV: {nodeEnv} @@ -182,7 +183,7 @@ const Index = ({ shows, nodeEnv }) => { ) } -Index.getInitialProps = async function () { +export async function getStaticProps(context) { const dev = process.env.CONTEXT !== 'production' // Set a random page between 1 and 100 @@ -196,7 +197,13 @@ Index.getInitialProps = async function () { const res = await fetch(server) const data = await res.json() - return { shows: data.slice(0, 5), nodeEnv: process.env.NODE_ENV || null } + return { + props: { + shows: data.slice(0, 5), + nodeEnv: process.env.NODE_ENV || null, + }, + revalidate: 60, + } } export default Index diff --git a/packages/runtime/src/helpers/redirects.ts b/packages/runtime/src/helpers/redirects.ts index e59ebba6c4..c1710bf7b2 100644 --- a/packages/runtime/src/helpers/redirects.ts +++ b/packages/runtime/src/helpers/redirects.ts @@ -148,8 +148,8 @@ const generateStaticIsrRewrites = ({ // appDir routes are a different format, so we need to handle them differently const isAppDir = isAppDirRoute(srcRoute, appPathRoutes) // The default locale is served from the root, not the localised path - if (i18n?.defaultLocale && route.startsWith(`/${i18n.defaultLocale}/`)) { - route = route.slice(i18n.defaultLocale.length + 1) + if (i18n?.defaultLocale && (route.startsWith(`/${i18n.defaultLocale}/`) || route === `/${i18n.defaultLocale}`)) { + route = route.slice(i18n.defaultLocale.length + 1) || '/' staticRoutePaths.add(route) if (matchesMiddleware(middleware, route)) { staticIsrRoutesThatMatchMiddleware.push(route) diff --git a/test/__snapshots__/index.spec.js.snap b/test/__snapshots__/index.spec.js.snap index 9c36a38c13..8854f5699a 100644 --- a/test/__snapshots__/index.spec.js.snap +++ b/test/__snapshots__/index.spec.js.snap @@ -637,10 +637,10 @@ Array [ "to": "/fr/", }, Object { - "force": false, + "force": true, "from": "/", "status": 200, - "to": "/.netlify/functions/___netlify-handler", + "to": "/.netlify/builders/___netlify-odb-handler", }, Object { "from": "/_ipx/*", @@ -822,10 +822,10 @@ Array [ "to": "/.netlify/functions/___netlify-handler", }, Object { - "force": false, + "force": true, "from": "/_next/data/build-id/en/index.json", "status": 200, - "to": "/.netlify/functions/___netlify-handler", + "to": "/.netlify/builders/___netlify-odb-handler", }, Object { "force": false, @@ -881,6 +881,12 @@ Array [ "status": 200, "to": "/.netlify/functions/___netlify-handler", }, + Object { + "force": true, + "from": "/_next/data/build-id/es.json", + "status": 200, + "to": "/.netlify/builders/___netlify-odb-handler", + }, Object { "force": false, "from": "/_next/data/build-id/es/500.json", @@ -1019,12 +1025,6 @@ Array [ "status": 200, "to": "/.netlify/functions/___netlify-handler", }, - Object { - "force": false, - "from": "/_next/data/build-id/es/index.json", - "status": 200, - "to": "/.netlify/functions/___netlify-handler", - }, Object { "force": false, "from": "/_next/data/build-id/es/layouts.json", @@ -1079,6 +1079,12 @@ Array [ "status": 200, "to": "/.netlify/functions/___netlify-handler", }, + Object { + "force": true, + "from": "/_next/data/build-id/fr.json", + "status": 200, + "to": "/.netlify/builders/___netlify-odb-handler", + }, Object { "force": false, "from": "/_next/data/build-id/fr/500.json", @@ -1217,12 +1223,6 @@ Array [ "status": 200, "to": "/.netlify/functions/___netlify-handler", }, - Object { - "force": false, - "from": "/_next/data/build-id/fr/index.json", - "status": 200, - "to": "/.netlify/functions/___netlify-handler", - }, Object { "force": false, "from": "/_next/data/build-id/fr/layouts.json", @@ -1450,10 +1450,10 @@ Array [ "to": "/.netlify/functions/___netlify-handler", }, Object { - "force": false, - "from": "/es/", + "force": true, + "from": "/es", "status": 200, - "to": "/.netlify/functions/___netlify-handler", + "to": "/.netlify/builders/___netlify-odb-handler", }, Object { "force": false, @@ -1678,10 +1678,10 @@ Array [ "to": "/.netlify/functions/___netlify-handler", }, Object { - "force": false, - "from": "/fr/", + "force": true, + "from": "/fr", "status": 200, - "to": "/.netlify/functions/___netlify-handler", + "to": "/.netlify/builders/___netlify-odb-handler", }, Object { "force": false,