Skip to content

[Bug]: middleware on dynamic routes (deployed) #1168

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

Closed
2 tasks
JohnGemstone opened this issue Jan 26, 2022 · 7 comments · Fixed by #1171
Closed
2 tasks

[Bug]: middleware on dynamic routes (deployed) #1168

JohnGemstone opened this issue Jan 26, 2022 · 7 comments · Fixed by #1171
Labels
type: bug code to address defects in shipped code

Comments

@JohnGemstone
Copy link

JohnGemstone commented Jan 26, 2022

Summary

I'm using next middleware for A/B testing (by generating a cookie and rewrite to another URL depending on that cookie), but when using dynamic routes, I'm getting odd behavior. When I delete the cookie and revisit the page, the cookie is no longer generated. I've been able to reproduce the issue here with this site I made abtest-middleware.netlify.app. It compares the standard routing and dynamic behaviors.
Hopefully the repro site explains the issue well enough.

Works fine locally!

Steps to reproduce

  • Go to "/dynamic-routes"
  • Click "product-1" link
  • Observe cookie abstest-dynamic generated
  • Delete cookie
  • Refresh the page, navigate away and back to "product-1"
  • Observe no cookie is generated

Compare behavior to "/standard-routes"

A link to a reproduction repository

https://github.com/JohnGemstone/abtest-netlify-next

Plugin version

v4.2.1

More information about your build

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

What OS are you using?

Windows

Your netlify.toml file

No response

Your public/_redirects file

No response

Your next.config.js file

`next.config.js`
module.exports = {
  reactStrictMode: true,
}

Builds logs (or link to your logs)

Build logs
6:30:55 PM: Build ready to start
6:30:57 PM: build-image version: 122b31996ccaffd45d820a452d6227f8312110cc (focal)
6:30:57 PM: build-image tag: v4.5.3
6:30:57 PM: buildbot version: 44e4d661fad7f5ef0b9bffed6dfdedaa2c1ad008
6:30:57 PM: Fetching cached dependencies
6:30:58 PM: Starting to download cache of 158.3MB
6:30:58 PM: Finished downloading cache in 847.569167ms
6:30:58 PM: Starting to extract cache
6:31:03 PM: Finished extracting cache in 5.119017987s
6:31:03 PM: Finished fetching cache in 5.994004063s
6:31:03 PM: Starting to prepare the repo for build
6:31:04 PM: Preparing Git Reference refs/heads/main
6:31:04 PM: Parsing package.json dependencies
6:31:05 PM: Starting build script
6:31:05 PM: Installing dependencies
6:31:05 PM: Python version set to 2.7
6:31:05 PM: Started restoring cached node version
6:31:07 PM: Finished restoring cached node version
6:31:07 PM: v16.13.2 is already installed.
6:31:08 PM: Now using node v16.13.2 (npm v8.1.2)
6:31:08 PM: Started restoring cached build plugins
6:31:08 PM: Finished restoring cached build plugins
6:31:08 PM: Attempting ruby version 2.7.2, read from environment
6:31:09 PM: Using ruby version 2.7.2
6:31:09 PM: Using PHP version 8.0
6:31:09 PM: Started restoring cached node modules
6:31:09 PM: Finished restoring cached node modules
6:31:10 PM: Started restoring cached go cache
6:31:10 PM: Finished restoring cached go cache
6:31:10 PM: go version go1.16.5 linux/amd64
6:31:10 PM: go version go1.16.5 linux/amd64
6:31:10 PM: Installing missing commands
6:31:10 PM: Verify run directory
6:31:11 PM: ​
6:31:11 PM: ────────────────────────────────────────────────────────────────
6:31:11 PM:   Netlify Build                                                 
6:31:11 PM: ────────────────────────────────────────────────────────────────
6:31:11 PM: ​
6:31:11 PM: ❯ Version
6:31:11 PM:   @netlify/build 26.1.7
6:31:11 PM: ​
6:31:11 PM: ❯ Flags
6:31:11 PM:   baseRelDir: true
6:31:11 PM:   buildId: 61f1935e667774f72513d218
6:31:11 PM:   deployId: 61f1935e667774f72513d21a
6:31:11 PM: ​
6:31:11 PM: ❯ Current directory
6:31:11 PM:   /opt/build/repo
6:31:11 PM: ​
6:31:11 PM: ❯ Config file
6:31:11 PM:   No config file was defined: using default values.
6:31:11 PM: ​
6:31:11 PM: ❯ Context
6:31:11 PM:   production
6:31:12 PM: ​
6:31:12 PM: ❯ Installing plugins
6:31:12 PM:    - @netlify/[email protected]
6:31:13 PM: ​
6:31:13 PM: ❯ Loading plugins
6:31:13 PM:    - @netlify/[email protected] from Netlify app
6:31:15 PM: ​
6:31:15 PM: ────────────────────────────────────────────────────────────────
6:31:15 PM:   1. @netlify/plugin-nextjs (onPreBuild event)                  
6:31:15 PM: ────────────────────────────────────────────────────────────────
6:31:15 PM: ​
6:31:15 PM: Next.js cache restored.
6:31:15 PM: Netlify configuration property "build.environment.NEXT_PRIVATE_TARGET" value changed.
6:31:15 PM: ​
6:31:15 PM: (@netlify/plugin-nextjs onPreBuild completed in 95ms)
6:31:15 PM: ​
6:31:15 PM: ────────────────────────────────────────────────────────────────
6:31:15 PM:   2. Build command from Netlify app                             
6:31:15 PM: ────────────────────────────────────────────────────────────────
6:31:15 PM: ​
6:31:15 PM: $ npm run build
6:31:15 PM: > [email protected] build
6:31:15 PM: > next build
6:31:16 PM: info  - Checking validity of types...
6:31:16 PM: warn  - No ESLint configuration detected. Run next lint to begin setup
6:31:16 PM: info  - Creating an optimized production build...
6:31:16 PM: warn  - using beta Middleware (not covered by semver) - https://nextjs.org/docs/messages/beta-middleware
6:31:19 PM: info  - Compiled successfully
6:31:19 PM: info  - Collecting page data...
6:31:20 PM: info  - Generating static pages (0/15)
6:31:20 PM: info  - Generating static pages (3/15)
6:31:20 PM: info  - Generating static pages (7/15)
6:31:20 PM: info  - Generating static pages (11/15)
6:31:20 PM: info  - Generating static pages (15/15)
6:31:20 PM: info  - Finalizing page optimization...
6:31:21 PM: Page                                       Size     First Load JS
6:31:21 PM: ┌ ○ /                                      2.29 kB        73.8 kB
6:31:21 PM: ├   /_app                                  0 B            71.5 kB
6:31:21 PM: ├ ○ /404                                   194 B          71.7 kB
6:31:21 PM: ├ λ /api/hello                             0 B            71.5 kB
6:31:21 PM: ├ ○ /dynamic-routes                        2.31 kB        73.8 kB
6:31:21 PM: ├ ƒ /dynamic-routes/_middleware            649 B          97.4 kB
6:31:21 PM: ├ ● /dynamic-routes/[slug]                 2.57 kB        74.1 kB
6:31:21 PM: ├   ├ /dynamic-routes/product-0
6:31:21 PM: ├   ├ /dynamic-routes/product-1
6:31:21 PM: ├   └ /dynamic-routes/product-2
6:31:21 PM: ├ ● /dynamic-routes/test/[slug]            2.56 kB          74 kB
6:31:21 PM: ├   ├ /dynamic-routes/test/product-0
6:31:21 PM: ├   ├ /dynamic-routes/test/product-1
6:31:21 PM: ├   └ /dynamic-routes/test/product-2
6:31:21 PM: ├ ○ /standard-routes                       2.3 kB         73.8 kB
6:31:21 PM: ├ ƒ /standard-routes/_middleware           647 B          97.4 kB
6:31:21 PM: ├ ○ /standard-routes/product-a             2.49 kB          74 kB
6:31:21 PM: ├ ○ /standard-routes/product-b             2.51 kB          74 kB
6:31:21 PM: ├ ○ /standard-routes/product-c             2.49 kB          74 kB
6:31:21 PM: └ ○ /standard-routes/test/product-b        2.51 kB          74 kB
6:31:21 PM: + First Load JS shared by all              71.5 kB
6:31:21 PM:   ├ chunks/framework-6e4ba497ae0c8a3f.js   42 kB
6:31:21 PM:   ├ chunks/main-7e73d61bce33e887.js        28.2 kB
6:31:21 PM:   ├ chunks/pages/_app-9cd1d19dd7237c4c.js  493 B
6:31:21 PM:   ├ chunks/webpack-514908bffb652963.js     770 B
6:31:21 PM:   └ css/db4e57db63a2a6e9.css               1.9 kB
6:31:21 PM: ƒ  (Middleware)  intercepts requests (uses _middleware)
6:31:21 PM: λ  (Server)      server-side renders at runtime (uses getInitialProps or getServerSideProps)
6:31:21 PM: ○  (Static)      automatically rendered as static HTML (uses no initial props)
6:31:21 PM: ●  (SSG)         automatically generated as static HTML + JSON (uses getStaticProps)
6:31:21 PM: ​
6:31:21 PM: (build.command completed in 5.7s)
6:31:21 PM: ​
6:31:21 PM: ────────────────────────────────────────────────────────────────
6:31:21 PM:   3. @netlify/plugin-nextjs (onBuild event)                     
6:31:21 PM: ────────────────────────────────────────────────────────────────
6:31:21 PM: ​
6:31:21 PM: Patching /opt/build/repo/node_modules/next/dist/server/next-server.js
6:31:21 PM: Moving static page files to serve from CDN...
6:31:21 PM: Moved 1 files
6:31:21 PM: Skipped moving 18 files because they match middleware, so cannot be deployed to the CDN and will be served from the origin instead.
6:31:21 PM: This is fine, but we're letting you know because it may not be what you expect.
The following middleware matched statically-rendered pages:
6:31:21 PM: - /dynamic-routes/_middleware
6:31:21 PM: - /standard-routes/_middleware
6:31:21 PM: ────────────────────────────────────────────────────────────────
6:31:21 PM: The following files matched middleware and were not moved to the CDN:
6:31:21 PM: - dynamic-routes.html
6:31:21 PM: - standard-routes.html
6:31:21 PM: - dynamic-routes/product-0.html
6:31:21 PM: - dynamic-routes/product-0.json
6:31:21 PM: - dynamic-routes/product-1.html
6:31:21 PM: - dynamic-routes/product-1.json
6:31:21 PM: - dynamic-routes/product-2.html
6:31:21 PM: - dynamic-routes/product-2.json
6:31:21 PM: - standard-routes/product-a.html
6:31:21 PM: - standard-routes/product-b.html
6:31:21 PM: - standard-routes/product-c.html
6:31:21 PM: - dynamic-routes/test/product-0.html
6:31:21 PM: - dynamic-routes/test/product-0.json
6:31:21 PM: - dynamic-routes/test/product-1.html
6:31:21 PM: - dynamic-routes/test/product-1.json
6:31:21 PM: - dynamic-routes/test/product-2.html
6:31:21 PM: - dynamic-routes/test/product-2.json
6:31:21 PM: - standard-routes/test/product-b.html
6:31:21 PM: ────────────────────────────────────────────────────────────────
6:31:21 PM: Netlify configuration property "redirects" value changed to [
6:31:21 PM:   { from: '/_next/static/*', to: '/static/:splat', status: 200 },
6:31:21 PM:   {
6:31:21 PM:     from: '/_next/image*',
6:31:21 PM:     query: { url: ':url', w: ':width', q: ':quality' },
6:31:21 PM:     to: '/_ipx/w_:width,q_:quality/:url',
6:31:21 PM:     status: 301
6:31:21 PM:   },
6:31:21 PM:   { from: '/_ipx/*', to: '/.netlify/builders/_ipx', status: 200 },
6:31:21 PM:   { from: '/cache/*', to: '/404.html', status: 404, force: true },
6:31:21 PM:   { from: '/server/*', to: '/404.html', status: 404, force: true },
6:31:21 PM:   { from: '/serverless/*', to: '/404.html', status: 404, force: true },
6:31:21 PM:   { from: '/traces', to: '/404.html', status: 404, force: true },
6:31:21 PM:   {
6:31:21 PM:     from: '/routes-manifest.json',
6:31:21 PM:     to: '/404.html',
6:31:21 PM:     status: 404,
6:31:21 PM:     force: true
6:31:21 PM:   },
6:31:21 PM:   {
6:31:21 PM:     from: '/build-manifest.json',
6:31:21 PM:     to: '/404.html',
6:31:21 PM:     status: 404,
6:31:21 PM:     force: true
6:31:21 PM:   },
6:31:21 PM:   {
6:31:21 PM:     from: '/prerender-manifest.json',
6:31:21 PM:     to: '/404.html',
6:31:21 PM:     status: 404,
6:31:21 PM:     force: true
6:31:21 PM:   },
6:31:21 PM:   {
6:31:21 PM:     from: '/react-loadable-manifest.json',
6:31:21 PM:     to: '/404.html',
6:31:21 PM:     status: 404,
6:31:21 PM:     force: true
6:31:21 PM:   },
6:31:21 PM:   { from: '/BUILD_ID', to: '/404.html', status: 404, force: true },
6:31:21 PM:   {
6:31:21 PM:     from: '/api',
6:31:21 PM:     to: '/.netlify/functions/___netlify-handler',
6:31:21 PM:     status: 200
6:31:21 PM:   },
6:31:21 PM:   {
6:31:21 PM:     from: '/api/*',
6:31:21 PM:     to: '/.netlify/functions/___netlify-handler',
6:31:21 PM:     status: 200
6:31:21 PM:   },
6:31:21 PM:   {
6:31:21 PM:     from: '/favicon.ico',
6:31:21 PM:     to: '/favicon.ico',
6:31:21 PM:     conditions: { Cookie: [Array] },
6:31:21 PM:     status: 200
6:31:21 PM:   },
6:31:21 PM:   {
6:31:21 PM:     from: '/vercel.svg',
6:31:21 PM:     to: '/vercel.svg',
6:31:21 PM:     conditions: { Cookie: [Array] },
6:31:21 PM:     status: 200
6:31:21 PM:   },
6:31:21 PM:   {
6:31:21 PM:     from: '/*',
6:31:21 PM:     to: '/.netlify/functions/___netlify-handler',
6:31:21 PM:     status: 200,
6:31:21 PM:     conditions: { Cookie: [Array] },
6:31:21 PM:     force: true
6:31:21 PM:   },
6:31:21 PM:   {
6:31:21 PM:     from: '/_next/data/QfXkGnxehcJxNFXr5qX6B/index.json',
6:31:21 PM:     to: '/.netlify/functions/___netlify-handler',
6:31:21 PM:     status: 200,
6:31:21 PM:     force: false
6:31:21 PM:   },
6:31:21 PM:   {
6:31:21 PM:     from: '/',
6:31:21 PM:     to: '/.netlify/functions/___netlify-handler',
6:31:21 PM:     status: 200,
6:31:21 PM:     force: false
6:31:21 PM:   },
6:31:21 PM:   {
6:31:21 PM:     from: '/_next/data/QfXkGnxehcJxNFXr5qX6B/dynamic-routes.json',
6:31:21 PM:     to: '/.netlify/functions/___netlify-handler',
6:31:21 PM:     status: 200,
6:31:21 PM:     force: false
6:31:21 PM:   },
6:31:21 PM:   {
6:31:21 PM:     from: '/dynamic-routes',
6:31:21 PM:     to: '/.netlify/functions/___netlify-handler',
6:31:21 PM:     status: 200,
6:31:21 PM:     force: false
6:31:21 PM:   },
6:31:21 PM:   {
6:31:21 PM:     from: '/_next/data/QfXkGnxehcJxNFXr5qX6B/standard-routes.json',
6:31:21 PM:     to: '/.netlify/functions/___netlify-handler',
6:31:21 PM:     status: 200,
6:31:21 PM:     force: false
6:31:21 PM:   },
6:31:21 PM:   {
6:31:21 PM:     from: '/standard-routes',
6:31:21 PM:     to: '/.netlify/functions/___netlify-handler',
6:31:21 PM:     status: 200,
6:31:21 PM:     force: false
6:31:21 PM:   },
6:31:21 PM:   {
6:31:21 PM:     from: '/_next/data/QfXkGnxehcJxNFXr5qX6B/standard-routes/product-a.json',
6:31:21 PM:     to: '/.netlify/functions/___netlify-handler',
6:31:21 PM:     status: 200,
6:31:21 PM:     force: false
6:31:21 PM:   },
6:31:21 PM:   {
6:31:21 PM:     from: '/standard-routes/product-a',
6:31:21 PM:     to: '/.netlify/functions/___netlify-handler',
6:31:21 PM:     status: 200,
6:31:21 PM:     force: false
6:31:21 PM:   },
6:31:21 PM:   {
6:31:21 PM:     from: '/_next/data/QfXkGnxehcJxNFXr5qX6B/standard-routes/product-b.json',
6:31:21 PM:     to: '/.netlify/functions/___netlify-handler',
6:31:21 PM:     status: 200,
6:31:21 PM:     force: false
6:31:21 PM:   },
6:31:21 PM:   {
6:31:21 PM:     from: '/standard-routes/product-b',
6:31:21 PM:     to: '/.netlify/functions/___netlify-handler',
6:31:21 PM:     status: 200,
6:31:21 PM:     force: false
6:31:21 PM:   },
6:31:21 PM:   {
6:31:21 PM:     from: '/_next/data/QfXkGnxehcJxNFXr5qX6B/standard-routes/product-c.json',
6:31:21 PM:     to: '/.netlify/functions/___netlify-handler',
6:31:21 PM:     status: 200,
6:31:21 PM:     force: false
6:31:21 PM:   },
6:31:21 PM:   {
6:31:21 PM:     from: '/standard-routes/product-c',
6:31:21 PM:     to: '/.netlify/functions/___netlify-handler',
6:31:21 PM:     status: 200,
6:31:21 PM:     force: false
6:31:21 PM:   },
6:31:21 PM:   {
6:31:21 PM:     from: '/_next/data/QfXkGnxehcJxNFXr5qX6B/standard-routes/test/product-b.json',
6:31:21 PM:     to: '/.netlify/functions/___netlify-handler',
6:31:21 PM:     status: 200,
6:31:21 PM:     force: false
6:31:21 PM:   },
6:31:21 PM:   {
6:31:21 PM:     from: '/standard-routes/test/product-b',
6:31:21 PM:     to: '/.netlify/functions/___netlify-handler',
6:31:21 PM:     status: 200,
6:31:21 PM:     force: false
6:31:21 PM:   },
6:31:21 PM:   {
6:31:21 PM:     from: '/_next/data/QfXkGnxehcJxNFXr5qX6B/dynamic-routes/test/:slug.json',
6:31:21 PM:     to: '/.netlify/builders/___netlify-odb-handler',
6:31:21 PM:     status: 200,
6:31:21 PM:     force: false
6:31:21 PM:   },
6:31:21 PM:   {
6:31:21 PM:     from: '/dynamic-routes/test/:slug',
6:31:21 PM:     to: '/.netlify/builders/___netlify-odb-handler',
6:31:21 PM:     status: 200,
6:31:21 PM:     force: false
6:31:21 PM:   },
6:31:21 PM:   {
6:31:21 PM:     from: '/_next/data/QfXkGnxehcJxNFXr5qX6B/dynamic-routes/:slug.json',
6:31:21 PM:     to: '/.netlify/builders/___netlify-odb-handler',
6:31:21 PM:     status: 200,
6:31:21 PM:     force: false
6:31:21 PM:   },
6:31:21 PM:   {
6:31:21 PM:     from: '/dynamic-routes/:slug',
6:31:21 PM:     to: '/.netlify/builders/___netlify-odb-handler',
6:31:21 PM:     status: 200,
6:31:21 PM:     force: false
6:31:21 PM:   },
6:31:21 PM:   {
6:31:21 PM:     from: '/*',
6:31:21 PM:     to: '/.netlify/functions/___netlify-handler',
6:31:21 PM:     status: 200
6:31:21 PM:   }
6:31:21 PM: ].
6:31:21 PM: ​
6:31:21 PM: (@netlify/plugin-nextjs onBuild completed in 61ms)
6:31:21 PM: ​
6:31:21 PM: ────────────────────────────────────────────────────────────────
6:31:21 PM:   4. Functions bundling                                         
6:31:21 PM: ────────────────────────────────────────────────────────────────
6:31:21 PM: ​
6:31:21 PM: Packaging Functions from .netlify/functions-internal directory:
6:31:21 PM:  - ___netlify-handler/___netlify-handler.js
6:31:21 PM:  - ___netlify-odb-handler/___netlify-odb-handler.js
6:31:21 PM:  - _ipx/_ipx.js
6:31:21 PM: ​
6:31:38 PM: ​
6:31:38 PM: (Functions bundling completed in 17.1s)
6:31:38 PM: ​
6:31:38 PM: ────────────────────────────────────────────────────────────────
6:31:38 PM:   5. @netlify/plugin-nextjs (onPostBuild event)                 
6:31:38 PM: ────────────────────────────────────────────────────────────────
6:31:38 PM: ​
6:31:38 PM: Next.js cache saved.
6:31:38 PM: ​
6:31:38 PM: (@netlify/plugin-nextjs onPostBuild completed in 72ms)
6:31:38 PM: ​
6:31:38 PM: ────────────────────────────────────────────────────────────────
6:31:38 PM:   6. Deploy site                                                
6:31:38 PM: ────────────────────────────────────────────────────────────────
6:31:38 PM: ​
6:31:38 PM: Starting to deploy site from '.next'
6:31:38 PM: Creating deploy tree 
6:31:38 PM: Creating deploy upload records
6:31:38 PM: 31 new files to upload
6:31:38 PM: 3 new functions to upload
6:31:47 PM: Site deploy was successfully initiated
6:31:47 PM: ​
6:31:47 PM: (Deploy site completed in 9.3s)
6:31:47 PM: ​
6:31:47 PM: ────────────────────────────────────────────────────────────────
6:31:47 PM:   Netlify Build Complete                                        
6:31:47 PM: ────────────────────────────────────────────────────────────────
6:31:47 PM: ​
6:31:47 PM: (Netlify Build completed in 35.9s)
6:31:47 PM: Starting post processing
6:31:48 PM: Post processing - HTML
6:31:48 PM: Caching artifacts
6:31:48 PM: Started saving node modules
6:31:48 PM: Finished saving node modules
6:31:48 PM: Started saving build plugins
6:31:48 PM: Finished saving build plugins
6:31:48 PM: Started saving pip cache
6:31:48 PM: Finished saving pip cache
6:31:48 PM: Started saving emacs cask dependencies
6:31:48 PM: Finished saving emacs cask dependencies
6:31:48 PM: Started saving maven dependencies
6:31:48 PM: Finished saving maven dependencies
6:31:48 PM: Started saving boot dependencies
6:31:48 PM: Finished saving boot dependencies
6:31:48 PM: Started saving rust rustup cache
6:31:48 PM: Finished saving rust rustup cache
6:31:48 PM: Started saving go dependencies
6:31:48 PM: Finished saving go dependencies
6:31:48 PM: Build script success
6:31:49 PM: Post processing - header rules
6:31:49 PM: Post processing - redirect rules
6:31:49 PM: Post processing done
6:31:49 PM: Site is live ✨
6:32:12 PM: Finished processing build request in 1m14.544783547s

Function logs

No response

.next JSON files

generated .next JSON files

.next/required-server-files.json

{"version":1,"config":{"env":{},"webpack":null,"webpackDevMiddleware":null,"eslint":{"ignoreDuringBuilds":false},"typescript":{"ignoreBuildErrors":false,"tsconfigPath":"tsconfig.json"},"distDir":".next","cleanDistDir":true,"assetPrefix":"","configOrigin":"next.config.js","useFileSystemPublicRoutes":true,"generateEtags":true,"pageExtensions":["tsx","ts","jsx","js"],"target":"server","poweredByHeader":true,"compress":false,"analyticsId":"","images":{"deviceSizes":[640,750,828,1080,1200,1920,2048,3840],"imageSizes":[16,32,48,64,96,128,256,384],"path":"/_next/image","loader":"default","domains":[],"disableStaticImages":false,"minimumCacheTTL":60,"formats":["image/webp"]},"devIndicators":{"buildActivity":true,"buildActivityPosition":"bottom-right"},"onDemandEntries":{"maxInactiveAge":15000,"pagesBufferLength":2},"amp":{"canonicalBase":""},"basePath":"","sassOptions":{},"trailingSlash":false,"i18n":null,"productionBrowserSourceMaps":false,"optimizeFonts":true,"excludeDefaultMomentLocales":true,"serverRuntimeConfig":{},"publicRuntimeConfig":{},"reactStrictMode":true,"httpAgentOptions":{"keepAlive":true},"outputFileTracing":true,"staticPageGenerationTimeout":60,"swcMinify":false,"experimental":{"cpus":7,"sharedPool":true,"plugins":false,"profiling":false,"isrFlushToDisk":true,"workerThreads":false,"pageEnv":false,"optimizeImages":false,"optimizeCss":false,"scrollRestoration":false,"externalDir":false,"reactRoot":false,"disableOptimizedLoading":false,"gzipSize":true,"swcFileReading":true,"craCompat":false,"esmExternals":true,"isrMemoryCacheSize":52428800,"concurrentFeatures":false,"serverComponents":false,"fullySpecified":false,"outputFileTracingRoot":"","outputStandalone":false},"configFileName":"next.config.js"},"appDir":"/opt/build/repo","files":[".next/routes-manifest.json",".next/server/pages-manifest.json",".next/build-manifest.json",".next/prerender-manifest.json",".next/server/middleware-manifest.json",".next/react-loadable-manifest.json",".next/server/font-manifest.json",".next/BUILD_ID"],"ignore":["node_modules/next/dist/compiled/@ampproject/toolbox-optimizer/**/*"]}

.next/routes-manifest.json

{"version":3,"pages404":true,"basePath":"","redirects":[{"source":"/:path+/","destination":"/:path+","internal":true,"statusCode":308,"regex":"^(?:/((?:[^/]+?)(?:/(?:[^/]+?))*))/$"}],"headers":[],"dynamicRoutes":[{"page":"/dynamic-routes/test/[slug]","regex":"^/dynamic\\-routes/test/([^/]+?)(?:/)?$","routeKeys":{"slug":"slug"},"namedRegex":"^/dynamic\\-routes/test/(?<slug>[^/]+?)(?:/)?$"},{"page":"/dynamic-routes/[slug]","regex":"^/dynamic\\-routes/([^/]+?)(?:/)?$","routeKeys":{"slug":"slug"},"namedRegex":"^/dynamic\\-routes/(?<slug>[^/]+?)(?:/)?$"}],"staticRoutes":[{"page":"/","regex":"^/(?:/)?$","routeKeys":{},"namedRegex":"^/(?:/)?$"},{"page":"/dynamic-routes","regex":"^/dynamic\\-routes(?:/)?$","routeKeys":{},"namedRegex":"^/dynamic\\-routes(?:/)?$"},{"page":"/standard-routes","regex":"^/standard\\-routes(?:/)?$","routeKeys":{},"namedRegex":"^/standard\\-routes(?:/)?$"},{"page":"/standard-routes/product-a","regex":"^/standard\\-routes/product\\-a(?:/)?$","routeKeys":{},"namedRegex":"^/standard\\-routes/product\\-a(?:/)?$"},{"page":"/standard-routes/product-b","regex":"^/standard\\-routes/product\\-b(?:/)?$","routeKeys":{},"namedRegex":"^/standard\\-routes/product\\-b(?:/)?$"},{"page":"/standard-routes/product-c","regex":"^/standard\\-routes/product\\-c(?:/)?$","routeKeys":{},"namedRegex":"^/standard\\-routes/product\\-c(?:/)?$"},{"page":"/standard-routes/test/product-b","regex":"^/standard\\-routes/test/product\\-b(?:/)?$","routeKeys":{},"namedRegex":"^/standard\\-routes/test/product\\-b(?:/)?$"}],"dataRoutes":[{"page":"/dynamic-routes/test/[slug]","routeKeys":{"slug":"slug"},"dataRouteRegex":"^/_next/data/QfXkGnxehcJxNFXr5qX6B/dynamic\\-routes/test/([^/]+?)\\.json$","namedDataRouteRegex":"^/_next/data/QfXkGnxehcJxNFXr5qX6B/dynamic\\-routes/test/(?<slug>[^/]+?)\\.json$"},{"page":"/dynamic-routes/[slug]","routeKeys":{"slug":"slug"},"dataRouteRegex":"^/_next/data/QfXkGnxehcJxNFXr5qX6B/dynamic\\-routes/([^/]+?)\\.json$","namedDataRouteRegex":"^/_next/data/QfXkGnxehcJxNFXr5qX6B/dynamic\\-routes/(?<slug>[^/]+?)\\.json$"}],"rewrites":[]}

.next/prerender-manifest.json

{"version":3,"routes":{"/dynamic-routes/product-0":{"initialRevalidateSeconds":false,"srcRoute":"/dynamic-routes/[slug]","dataRoute":"/_next/data/QfXkGnxehcJxNFXr5qX6B/dynamic-routes/product-0.json"},"/dynamic-routes/product-1":{"initialRevalidateSeconds":false,"srcRoute":"/dynamic-routes/[slug]","dataRoute":"/_next/data/QfXkGnxehcJxNFXr5qX6B/dynamic-routes/product-1.json"},"/dynamic-routes/product-2":{"initialRevalidateSeconds":false,"srcRoute":"/dynamic-routes/[slug]","dataRoute":"/_next/data/QfXkGnxehcJxNFXr5qX6B/dynamic-routes/product-2.json"},"/dynamic-routes/test/product-0":{"initialRevalidateSeconds":false,"srcRoute":"/dynamic-routes/test/[slug]","dataRoute":"/_next/data/QfXkGnxehcJxNFXr5qX6B/dynamic-routes/test/product-0.json"},"/dynamic-routes/test/product-1":{"initialRevalidateSeconds":false,"srcRoute":"/dynamic-routes/test/[slug]","dataRoute":"/_next/data/QfXkGnxehcJxNFXr5qX6B/dynamic-routes/test/product-1.json"},"/dynamic-routes/test/product-2":{"initialRevalidateSeconds":false,"srcRoute":"/dynamic-routes/test/[slug]","dataRoute":"/_next/data/QfXkGnxehcJxNFXr5qX6B/dynamic-routes/test/product-2.json"}},"dynamicRoutes":{"/dynamic-routes/[slug]":{"routeRegex":"^/dynamic\\-routes/([^/]+?)(?:/)?$","dataRoute":"/_next/data/QfXkGnxehcJxNFXr5qX6B/dynamic-routes/[slug].json","fallback":false,"dataRouteRegex":"^/_next/data/QfXkGnxehcJxNFXr5qX6B/dynamic\\-routes/([^/]+?)\\.json$"},"/dynamic-routes/test/[slug]":{"routeRegex":"^/dynamic\\-routes/test/([^/]+?)(?:/)?$","dataRoute":"/_next/data/QfXkGnxehcJxNFXr5qX6B/dynamic-routes/test/[slug].json","fallback":false,"dataRouteRegex":"^/_next/data/QfXkGnxehcJxNFXr5qX6B/dynamic\\-routes/test/([^/]+?)\\.json$"}},"notFoundRoutes":[],"preview":{"previewModeId":"0bb2028ec42375c35516c0c9a5b74e5c","previewModeSigningKey":"d6921b05d37d0177aa621e43820565de92f7a4963f8c5ca9341e0d478201c200","previewModeEncryptionKey":"3999c0787d7edf11903f21d4593aca7efcf5b8d33079f968f3e1d632b629a209"}}
@JohnGemstone JohnGemstone added the type: bug code to address defects in shipped code label Jan 26, 2022
@ascorbic
Copy link
Contributor

Hi @JohnGemstone. Thanks for the report. I think this is essentially the same issue as #1114, but your excellent repro has helped me identify an actual bug in our rewrite handling code. Currently we need to run middleware at the origin, so we have to work around when there are static pages that would otherwise be served by the CDN. It seems that what we're missing is the case where dynamic pages have fallback=false and are statically-rendered. We correctly skip moving them to the CDN, but we don't ensure they use the SSR handler. Instead they are using an on-demand builder, which persists the first response (because usually it would just be generating the 404 page). I will fix that.

@ascorbic
Copy link
Contributor

I'm going to close this in favour of #1114, so please do subscribe there to keep track of this.

@JohnGemstone
Copy link
Author

Thanks for the quick turn around with this @ascorbic and reviewers.
Everything works as expected now!
https://abtest-middleware.netlify.app/

Will update the issue with the old branch URL for preservation's sake.

@ascorbic
Copy link
Contributor

ascorbic commented Feb 2, 2022

Great! Thanks for letting us know.

@JohnGemstone
Copy link
Author

Just been told that any redirects declared in netlify.toml pointing to middleware routes are throwing 404 ☠. Is the best way around this to declare them in the next.config?

@ascorbic
Copy link
Contributor

ascorbic commented Feb 7, 2022

Hi @JohnGemstone ,
Yes, it's best to use the Next config for that.

@JohnGemstone
Copy link
Author

Hey @ascorbic, I've given it a go, and now I'm experiencing another bug. It's a bit of a narrow case but it seems like if you arrive at a middleware route from a next-rewrite, the middleware rewrite response is ignored.

I have reproduced using the example above (make sure the cookie abtest-dynamic is set to test)
https://abtest-middleware.netlify.app/product-landing

My next config
module.exports = {
  reactStrictMode: true,
  async rewrites() {
    return [
      {
        source: '/product-landing',
        destination: '/dynamic-routes/product-1',
      },
    ]
  },
}

I'll have a look to see if this can be side stepped using redirects instead, I guess part of the problem is having rewrites on rewrites!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants