Description
preview mode on netlify works as such:
for all pre-rendered getStaticProps pages, we add a cookie-based redirect to _redirects that redirects to a serverless function (wrapping the lambda for that page), only when the next.js preview mode cookies are present. see: https://github.com/netlify/netlify-plugin-nextjs/blob/main/src/lib/pages/getStaticProps/redirects.js#L42-L52
for example:
/getStaticProps/1 /.netlify/functions/next_getStaticProps_id 200! Cookie=__prerender_bypass,__next_preview_data
/getStaticProps/2 /.netlify/functions/next_getStaticProps_id 200! Cookie=__prerender_bypass,__next_preview_data
/getStaticProps/static /.netlify/functions/next_getStaticProps_static 200! Cookie=__prerender_bypass,__next_preview_data
/getStaticProps/withFallback/3 /.netlify/functions/next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data
/getStaticProps/withFallback/4 /.netlify/functions/next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data
this means, if no cookie is present, we serve the static, prerendered html to /getStaticProps/1. if the cookies are present, we redirect to the function to SSR for preview mode.
prior to us adding ODB support for pages with fallback, this worked fine. for /getStaticProps/withFallback/3, we'd fall back to the serverless function to SSR the preview content. however, now that we use builder functions for these pages (instead of standard functions), it'll always cache the first built page in preview mode.
the simplest solution i see:
for these page types (getStaticPropsWithFallback), add a standard function and a builder function (ODB), appended with either a standard
or builder
label to differentiate the two. then, we'd add one redirect to the builder function by default (which we already do), and one cookie-based redirect to the standard function (instead of to the builder function). i.e.:
/getStaticProps/withFallback/4 /.netlify/functions/next_getStaticProps_withFallback_id_standard 200! Cookie=__prerender_bypass,__next_preview_data
/getStaticProps/withFallback/:id /.netlify/functions/next_getStaticProps_withFallback_id_builder 200