Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Legacy fallback env var #2074

Merged
merged 23 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ The Next.js Runtime fully supports ISR on Netlify. For more details see

Note that Netlify has a minimum TTL of 60 seconds for revalidation.

## Disable Static 404 on Dynamic Routes with fallback:false

Currently when hitting a non-prerendered path with `fallback=false` it will default to a 404 page. You can now change this default setting by using the environemnt variable `LEGACY_FALLBACK_FALSE=true`. With the environment variable set, those non-prerendered paths will now be routed through using the ISR Handler and will allow you to add redirects for those non-prerendered paths.

## Use with `next export`

If you are using `next export` to generate a static site, you do not need most of the functionality of this Next.js
Expand Down
5 changes: 5 additions & 0 deletions demos/default/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ module.exports = {
destination: '/',
permanent: true,
},
{
source: '/getStaticProps/4/',
destination: '/',
permanent: true,
},
]
},
// https://nextjs.org/docs/basic-features/image-optimization#domains
Expand Down
57 changes: 34 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions packages/runtime/src/helpers/redirects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ const generateStaticIsrRewrites = ({
/**
* Generate rewrites for all dynamic routes
*/
const generateDynamicRewrites = ({
export const generateDynamicRewrites = ({
dynamicRoutes,
prerenderedDynamicRoutes,
middleware,
Expand Down Expand Up @@ -238,7 +238,11 @@ const generateDynamicRewrites = ({
withData: true,
}),
)
} else if (prerenderedDynamicRoutes[route.page].fallback === false && !is404Isr) {
} else if (
prerenderedDynamicRoutes[route.page].fallback === false &&
!is404Isr &&
!process.env.LEGACY_FALLBACK_FALSE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work if folks use LEGACY_FALLBACK_FALSE = 'false' so we need to test for strings too. In other areas of the Runtime we've used destr so I'd suggest that as a convention: https://github.com/netlify/next-runtime/blob/split-api-routes/packages/runtime/src/index.ts#L106

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the heads up Rob and the ref code.

) {
dynamicRewrites.push(...redirectsForNext404Route({ route: route.page, buildId, basePath, i18n }))
} else {
dynamicRewrites.push(
Expand Down