next-runtime icon indicating copy to clipboard operation
next-runtime copied to clipboard

[Bug]: Edge Middleware Functions not executing when navigating to dynamic routes with next/link + matcher

Open JohnGemstone opened this issue 3 years ago • 1 comments

Summary

Similar to the issue we ran into here except with using the top level way of defining middleware Next 12.2.0 requires. Middleware functions are executed and run expectedly on prefetches to static routes. But no middleware functions are executed on navigation to dynamic pages, user must refresh the page.

Steps to reproduce

  1. Go to the Repo Demo
  2. Navigate to Prefetch Middleware test (static pages)
  3. Observe cookie creation of ab-static-* once navigating to the subpages (most likely will prefetch)
  4. Go back and navigate to Prefetch Middleware test (dynamic pages)
  5. Observe no cookie creation of ab-dynamic-* even when navigating to subpage.
  6. Refresh the subpage and observe cookie creation and rewrite as expected.

Works fine locally on netlify dev Can a work around removing the matcher config (preview)

A link to a reproduction repository

https://github.com/JohnGemstone/netlify-plugin-nextjs-middleware

Plugin version

4.12.2

More information about your build

  • [ ] I am building using the CLI
  • [X] I am building using file-based configuration (netlify.toml)

What OS are you using?

Mac OS

Your netlify.toml file

`netlify.toml`
[build]
publish = ".next"

[build.environment]
NEXT_USE_NETLIFY_EDGE = "true"

[[plugins]]
package = "@netlify/plugin-nextjs"

JohnGemstone avatar Jul 24 '22 16:07 JohnGemstone

As mentioned it works fine without the 'matcher config', but my concern is that without it the number of edge function invocations will increase tenfold depending on how many static files you access on each page.

JohnGemstone avatar Aug 01 '22 07:08 JohnGemstone