Skip to content

fix: match edge runtime pages with optional trailing slash #1892

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 3 commits into from
Jan 19, 2023

Conversation

ascorbic
Copy link
Contributor

Summary

Currently appDir edge runtime pages use the matcher regex to generate edge function pattern. However this regex is designed to match a normalised path, so doesn't include a trailing slash. This meant that some pages with the edge runtime did not match the edge function, causing server errors.

This PR changes edge functions to not use the regex from the matcher for pages, but instead use the regex from the routes manifest. This includes the optional trailing slash.

To make this work, I also refactored the handling of these matchers, splitting the generation of the functions from the creation of the matchers, and no longer use the same function for middleware and functions as they use different logic.

Test plan

  1. Visit the Deploy Preview (insert link to specific page) ...

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

Fixes #1798

image

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 18, 2023

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

Name Link
🔨 Latest commit 8252753
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-nx-monorepo-demo/deploys/63c94bd3c4fb02000a85670c
😎 Deploy Preview https://deploy-preview-1892--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 Jan 18, 2023

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

Name Link
🔨 Latest commit 8252753
🔍 Latest deploy log https://app.netlify.com/sites/next-plugin-edge-middleware/deploys/63c94bd33a27ed0008786452
😎 Deploy Preview https://deploy-preview-1892--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 Jan 18, 2023

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

Name Link
🔨 Latest commit 8252753
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-export-demo/deploys/63c94bd375af9f0009e761e9
😎 Deploy Preview https://deploy-preview-1892--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.

@github-actions github-actions bot added the type: bug code to address defects in shipped code label Jan 18, 2023
@netlify
Copy link

netlify bot commented Jan 18, 2023

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

Name Link
🔨 Latest commit 8252753
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-next-auth-demo/deploys/63c94bd37c163300083fc61a
😎 Deploy Preview https://deploy-preview-1892--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 Jan 18, 2023

Deploy Preview for next-i18next-demo ready!

Name Link
🔨 Latest commit 8252753
🔍 Latest deploy log https://app.netlify.com/sites/next-i18next-demo/deploys/63c94bd37c163300083fc61c
😎 Deploy Preview https://deploy-preview-1892--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 Jan 18, 2023

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

Name Link
🔨 Latest commit 8252753
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-demo/deploys/63c94bd370d477000932f203
😎 Deploy Preview https://deploy-preview-1892--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 Jan 18, 2023

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

Name Link
🔨 Latest commit 8252753
🔍 Latest deploy log https://app.netlify.com/sites/nextjs-plugin-custom-routes-demo/deploys/63c94bd369ac9400099ca0e3
😎 Deploy Preview https://deploy-preview-1892--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.

@netlify
Copy link

netlify bot commented Jan 18, 2023

Deploy Preview for next-plugin-canary ready!

Name Link
🔨 Latest commit 8252753
🔍 Latest deploy log https://app.netlify.com/sites/next-plugin-canary/deploys/63c94bd3aac7fa0008020b33
😎 Deploy Preview https://deploy-preview-1892--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 Jan 18, 2023

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

Name Link
🔨 Latest commit 8252753
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-static-root-demo/deploys/63c94bd339ef92000a7cc1f5
😎 Deploy Preview https://deploy-preview-1892--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.

@ascorbic ascorbic marked this pull request as ready for review January 18, 2023 19:51
@ascorbic ascorbic requested a review from a team January 18, 2023 19:51
Copy link
Contributor

@orinokai orinokai left a comment

Choose a reason for hiding this comment

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

🚀

@ascorbic ascorbic self-assigned this Jan 19, 2023
@@ -0,0 +1,23 @@
import type { Context } from 'https://edge.netlify.com'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've split this into a separate entrypoint, because functions don't need custom matcher handling or support for advanced middleware - but do want trailing slash handling unlike middleware


const matchesMiddleware: MiddlewareRouteMatch = getMiddlewareRouteMatcher(matchers || [])

export interface FetchEventResult {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved all of this into a shared file, so that we can have two separate entrypoints. They could go in a layer eventually.

Copy link

@nickytonline nickytonline left a comment

Choose a reason for hiding this comment

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

@kodiakhq kodiakhq bot merged commit 138b19d into main Jan 19, 2023
@kodiakhq kodiakhq bot deleted the mk/matcher-slash branch January 19, 2023 13:59
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.

Edge runtime routes throw 500 error on trailing slash mismatch
3 participants