Skip to content

fix: support named & default export for middleware in ntl dev #2116

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 7 commits into from
May 17, 2023

Conversation

LekoArts
Copy link

@LekoArts LekoArts commented May 16, 2023

Description

As explained in amannn/next-intl#290 (comment) it seems that both a named middleware export and a default export is supported.

This allows both for netlify dev when we import the middleware.

Documentation

N/A

Tests

No tests were added but I tried the change manually on the repository shared in #2106

You can test this change yourself like so:

  1. Existing E2E middleware should continue to work
  2. [Bug]: Upgrading @netlify/plugin-nextjs to 4.36.1 breaks he usage with next-intl #2106

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

Fixes #2106

@LekoArts LekoArts requested a review from a team as a code owner May 16, 2023 08:46
@netlify
Copy link

netlify bot commented May 16, 2023

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

Name Link
🔨 Latest commit 39c106f
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-next-auth-demo/deploys/64646a80e09683000885597b
😎 Deploy Preview https://deploy-preview-2116--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 May 16, 2023

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

Name Link
🔨 Latest commit 39c106f
🔍 Latest deploy log https://app.netlify.com/sites/nextjs-plugin-custom-routes-demo/deploys/64646a8029ff0e0008914c00
😎 Deploy Preview https://deploy-preview-2116--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 May 16, 2023

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

Name Link
🔨 Latest commit 39c106f
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-demo/deploys/64646a819c367e00086ee1bc
😎 Deploy Preview https://deploy-preview-2116--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 May 16, 2023

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

Name Link
🔨 Latest commit 39c106f
🔍 Latest deploy log https://app.netlify.com/sites/next-plugin-edge-middleware/deploys/64646a8057934a0008b39dbf
😎 Deploy Preview https://deploy-preview-2116--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 May 16, 2023

Deploy Preview for next-i18next-demo ready!

Name Link
🔨 Latest commit 39c106f
🔍 Latest deploy log https://app.netlify.com/sites/next-i18next-demo/deploys/64646a80bfa640000863fd74
😎 Deploy Preview https://deploy-preview-2116--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 May 16, 2023

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

Name Link
🔨 Latest commit 39c106f
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-static-root-demo/deploys/64646a80378f210008f4a251
😎 Deploy Preview https://deploy-preview-2116--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 May 16, 2023

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

Name Link
🔨 Latest commit 39c106f
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-nx-monorepo-demo/deploys/64646a809c367e00086ee1b7
😎 Deploy Preview https://deploy-preview-2116--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 May 16, 2023

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

Name Link
🔨 Latest commit 39c106f
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-export-demo/deploys/64646a8081316900083b7c72
😎 Deploy Preview https://deploy-preview-2116--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 May 16, 2023

Deploy Preview for next-plugin-canary ready!

Name Link
🔨 Latest commit 39c106f
🔍 Latest deploy log https://app.netlify.com/sites/next-plugin-canary/deploys/64646a806ab1e800086f4bba
😎 Deploy Preview https://deploy-preview-2116--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.

@github-actions github-actions bot added the type: bug code to address defects in shipped code label May 16, 2023
@LekoArts LekoArts self-assigned this May 16, 2023
middleware = nextMiddleware.middleware

// The middleware file can export a named `middleware` export or a `default` export
middleware = isFunction(nextMiddleware.middleware) ? nextMiddleware.middleware : nextMiddleware.default

Choose a reason for hiding this comment

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

Is the function check necessary? I imagine nextMiddleware.middleware is undefined if the default exists?

Suggested change
middleware = isFunction(nextMiddleware.middleware) ? nextMiddleware.middleware : nextMiddleware.default
middleware = nextMiddleware.middleware ?? nextMiddleware.default

Copy link
Author

Choose a reason for hiding this comment

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

Someone could for some reason export a named middleware that is for them some utility. Better safe than sorry

@pieh pieh added the automerge label May 17, 2023
@kodiakhq kodiakhq bot merged commit b31f858 into main May 17, 2023
@kodiakhq kodiakhq bot deleted the ntl-dev-middleware-exports branch May 17, 2023 07:37
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.

[Bug]: Upgrading @netlify/plugin-nextjs to 4.36.1 breaks he usage with next-intl
4 participants