Skip to content

feat: cache redirects for 60 seconds if no ttl provided #1677

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

Merged
merged 1 commit into from
Oct 12, 2022

Conversation

orinokai
Copy link
Contributor

@orinokai orinokai commented Oct 11, 2022

Summary

Next.js uses 307 and 308 codes for its redirects, but our ODB functions currently only invalidate cached content for 200, 301 and 404 codes. This means ISR pages that conditionally return a redirect are not updating as expected.

A fix to Netlify Proxy for the above issue is currently in progress and this PR is a corresponding fix for a specific Next.js case: ISR pages with redirects, but without a revalidate value, are returned to the ODB with a default max-age of 1 year, which causes the ODB to cache them indefinitely. This PR ensures that redirects without revalidate are cached ephemerally for 60s.

Test plan

Visit /getStaticProps/with-revalidate-redirect/ on the demo site deploy preview and observe that the page should redirect if the last digit of the current minute is 0-4 and should show a successful 200 response if the last digit is 5-9.
Unable to create a test page in the default demo because redirect cannot be returned when pre-rendering. Tests to follow in a new demo site.

Relevant links (GitHub issues, Notion docs, etc.)

netlify/pillar-runtime#443
netlify/proxy#950

@orinokai orinokai added the type: feature code contributing to the implementation of a feature and/or user facing functionality label Oct 11, 2022
@orinokai orinokai self-assigned this Oct 11, 2022
@netlify
Copy link

netlify bot commented Oct 11, 2022

Deploy Preview for netlify-plugin-nextjs-demo ready!

Name Link
🔨 Latest commit 2fb25ea
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-demo/deploys/6346aef8ffd5190008c232f5
😎 Deploy Preview https://deploy-preview-1677--netlify-plugin-nextjs-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Oct 11, 2022

Deploy Preview for netlify-plugin-nextjs-static-root-demo ready!

Name Link
🔨 Latest commit 2fb25ea
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-static-root-demo/deploys/6346aef87467250008c7ffc5
😎 Deploy Preview https://deploy-preview-1677--netlify-plugin-nextjs-static-root-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Oct 11, 2022

Deploy Preview for netlify-plugin-nextjs-export-demo ready!

Name Link
🔨 Latest commit 2fb25ea
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-export-demo/deploys/6346aef80908b20009f9fdcf
😎 Deploy Preview https://deploy-preview-1677--netlify-plugin-nextjs-export-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Oct 11, 2022

Deploy Preview for netlify-plugin-nextjs-nx-monorepo-demo ready!

Name Link
🔨 Latest commit 2fb25ea
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-nx-monorepo-demo/deploys/6346aef843d40700097a878e
😎 Deploy Preview https://deploy-preview-1677--netlify-plugin-nextjs-nx-monorepo-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Oct 11, 2022

Deploy Preview for next-plugin-edge-middleware ready!

Name Link
🔨 Latest commit 2fb25ea
🔍 Latest deploy log https://app.netlify.com/sites/next-plugin-edge-middleware/deploys/6346aef8701057000bc73282
😎 Deploy Preview https://deploy-preview-1677--next-plugin-edge-middleware.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Oct 11, 2022

Deploy Preview for next-i18next-demo ready!

Name Link
🔨 Latest commit 2fb25ea
🔍 Latest deploy log https://app.netlify.com/sites/next-i18next-demo/deploys/6346aef8f07a7d0008183bf2
😎 Deploy Preview https://deploy-preview-1677--next-i18next-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Oct 11, 2022

Deploy Preview for next-plugin-rsc-demo ready!

Name Link
🔨 Latest commit 2fb25ea
🔍 Latest deploy log https://app.netlify.com/sites/next-plugin-rsc-demo/deploys/6346aef8eb929b0007cfe47d
😎 Deploy Preview https://deploy-preview-1677--next-plugin-rsc-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Oct 11, 2022

Deploy Preview for netlify-plugin-nextjs-next-auth-demo ready!

Name Link
🔨 Latest commit 2fb25ea
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-next-auth-demo/deploys/6346aef826d28b000a8ea1a7
😎 Deploy Preview https://deploy-preview-1677--netlify-plugin-nextjs-next-auth-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Oct 11, 2022

Deploy Preview for next-plugin-canary ready!

Name Link
🔨 Latest commit 2fb25ea
🔍 Latest deploy log https://app.netlify.com/sites/next-plugin-canary/deploys/6346aef8922bf4000a8fc9c8
😎 Deploy Preview https://deploy-preview-1677--next-plugin-canary.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Oct 11, 2022

Deploy Preview for nextjs-plugin-custom-routes-demo ready!

Name Link
🔨 Latest commit 2fb25ea
🔍 Latest deploy log https://app.netlify.com/sites/nextjs-plugin-custom-routes-demo/deploys/6346aef8711a2c000a5f5555
😎 Deploy Preview https://deploy-preview-1677--nextjs-plugin-custom-routes-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@orinokai orinokai marked this pull request as ready for review October 11, 2022 18:25
@orinokai orinokai requested a review from a team October 11, 2022 18:25
@nickytonline
Copy link

@orinokai, can we add an end to end test for this fix or is it not possible atm as we'd need to wait at least 60 seconds for it to invalidate?

@orinokai
Copy link
Contributor Author

@nickytonline the main problem with adding a test is that the site won’t build when there is a redirect in getStaticProps so we’d need a way to ensure it only returns a redirect after the initial build. I have a plan but it involves creating a new demo site with a timestamp as the build ID and then setting up some long running Cypress tests. Since that will take some time and this is an urgent fix, I’d planned to do that as a separate bit of work.

@nickytonline
Copy link

@nickytonline the main problem with adding a test is that the site won’t build when there is a redirect in getStaticProps so we’d need a way to ensure it only returns a redirect after the initial build. I have a plan but it involves creating a new demo site with a timestamp as the build ID and then setting up some long running Cypress tests. Since that will take some time and this is an urgent fix, I’d planned to do that as a separate bit of work.

Sounds good. I'll create an issue for it.

@kodiakhq kodiakhq bot merged commit 23d8d3b into main Oct 12, 2022
@kodiakhq kodiakhq bot deleted the rs/redirect-ttls branch October 12, 2022 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge type: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants