Skip to content

fix: add specific rewrites for all SSR routes #1105

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 4 commits into from
Jan 11, 2022
Merged

Conversation

ascorbic
Copy link
Contributor

@ascorbic ascorbic commented Jan 7, 2022

Summary

Currently (with some exceptions) we only add rewrites for routes that need to use an ODB, and rely on a catch-all to rewrite the rest to the regular handler. However this causes problems when an ODB dynamic route overrides a static SSR route, because it never falls-back to the catch-all. This leads to bugs due to it unexpectedly using an ODB, so having the wrong cache behaviour and missing query data etc.

This PR changes the rewrite handling to generate rewrites for every route, including SSR. These are done starting with the most specific, static routes and then the dynamic routes as defined in the routes manifest. We look these up in the prerender manifest so we can see which need ODB and which SSR handlers.

This does lead to a lot of rewrites, particularly for sites with i18n, because we need to generate separate rewrites for all of them. There may be a way to simplify these rewrites, collapsing some into single rules. However I don't want to attempt this until we have better tests.

I have been working on tests, but have had to abandon my original plan because it's really hard to isolate them and just test the rewrites. It looks like the best bet will be to do a new integration test suite, where we do a full build, then use the plugin to generate a toml and run ntl dev, then use fetch and check the x-render-mode for each page. We could in theory also do this with cypress. I will investigate further and do a follow-up PR

Test plan

  1. Load all the pages in the demo site, checking in dev tools to ensure the JSON works properly and then reload each page to ensure the HTML does too. Then switch to the French locale and try again.

Relevant links (GitHub issues, Notion docs, etc.) or a picture of cute animal

capybara

Fixes #1077, fixes #1068

Standard checks:

  • Check the Deploy Preview's Demo site for your PR's functionality
  • Add docs when necessary

🧪 Once merged, make sure to update the version if needed and that it was published correctly.

@netlify
Copy link

netlify bot commented Jan 7, 2022

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

🔨 Explore the source changes: 8be8a32

🔍 Inspect the deploy log: https://app.netlify.com/sites/netlify-plugin-nextjs-demo/deploys/61dd5c637ecf480007a7dd5b

😎 Browse the preview: https://deploy-preview-1105--netlify-plugin-nextjs-demo.netlify.app

@ascorbic ascorbic requested a review from a team January 7, 2022 17:43
@ascorbic ascorbic self-assigned this Jan 7, 2022
@github-actions github-actions bot added the type: bug code to address defects in shipped code label Jan 7, 2022
@netlify
Copy link

netlify bot commented Jan 7, 2022

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

🔨 Explore the source changes: 8be8a32

🔍 Inspect the deploy log: https://app.netlify.com/sites/netlify-plugin-nextjs-static-root-demo/deploys/61dd5c63816e2d000852745c

😎 Browse the preview: https://deploy-preview-1105--netlify-plugin-nextjs-static-root-demo.netlify.app

@netlify
Copy link

netlify bot commented Jan 7, 2022

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

🔨 Explore the source changes: 8be8a32

🔍 Inspect the deploy log: https://app.netlify.com/sites/netlify-plugin-nextjs-nx-monorepo-demo/deploys/61dd5c6314e55d0007c9307e

😎 Browse the preview: https://deploy-preview-1105--netlify-plugin-nextjs-nx-monorepo-demo.netlify.app/

@netlify
Copy link

netlify bot commented Jan 7, 2022

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

🔨 Explore the source changes: 8be8a32

🔍 Inspect the deploy log: https://app.netlify.com/sites/netlify-plugin-nextjs-export-demo/deploys/61dd5c637bf7110007b35c4d

😎 Browse the preview: https://deploy-preview-1105--netlify-plugin-nextjs-export-demo.netlify.app

@cypress
Copy link

cypress bot commented Jan 7, 2022



Test summary

17 0 0 0


Run details

Project netlify-plugin-nextjs-default-demo
Status Passed
Commit 8be8a32
Started Jan 11, 2022 10:38 AM
Ended Jan 11, 2022 10:40 AM
Duration 02:17 💡
OS Linux Ubuntu - 20.04
Browser Custom chromium 90

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@cypress
Copy link

cypress bot commented Jan 7, 2022



Test summary

7 0 0 0


Run details

Project netlify-plugin-nextjs-static-demo
Status Passed
Commit 8be8a32
Started Jan 11, 2022 10:35 AM
Ended Jan 11, 2022 10:37 AM
Duration 01:21 💡
OS Linux Ubuntu - 20.04
Browser Custom chromium 90

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@cypress
Copy link

cypress bot commented Jan 7, 2022



Test summary

2 0 0 0


Run details

Project netlify-plugin-nextjs-nx-monorepo-demo
Status Passed
Commit 8be8a32
Started Jan 11, 2022 10:38 AM
Ended Jan 11, 2022 10:39 AM
Duration 01:20 💡
OS Linux Ubuntu - 20.04
Browser Custom chromium 90

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

tiffafoo
tiffafoo previously approved these changes Jan 10, 2022
Copy link

@tiffafoo tiffafoo left a comment

Choose a reason for hiding this comment

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

👯‍♀️ demos look good

tiffafoo
tiffafoo previously approved these changes Jan 11, 2022
@tiffafoo
Copy link

CleanShot 2022-01-11 at 12 15 06@2x

👈😎👈

@kodiakhq kodiakhq bot merged commit 6fd7bcc into main Jan 11, 2022
@kodiakhq kodiakhq bot deleted the mk/ssr-rewrites branch January 11, 2022 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dynamic ODB routes take precedence over specific SSR routes [Bug]: Query string not populated for getServerSideProps
2 participants