nextjs - 💡(How to fix) Fix beforeFiles rewrites with locale: false and has conditions stopped firing in 16.2.0 [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#92451Fetched 2026-04-08 02:59:55
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Author
Timeline (top)
closed ×1commented ×1labeled ×1locked ×1

Root Cause

  • The rewrite config is verified correct in the resolved Next.js config at build time
  • The has condition matches a query parameter (not a header or cookie)
  • The locale: false flag is required because the rewrite destination is an API route
  • Same config works perfectly on 16.1.7 and earlier

Code Example

async rewrites() {
  return {
    beforeFiles: [
      {
        source: '/:path(.*)',
        has: [
          {
            type: 'query',
            key: 'my-preview-token',
            value: '(?<token>.+)',
          },
        ],
        destination: '/api/my-handler',
        locale: false,
      },
    ],
    afterFiles: [],
    fallback: [],
  }
}
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/seth146/ksebe-headless-web (private repo — reproduction details below)

To Reproduce

  1. Configure Next.js with Pages Router and domain-based i18n
  2. Add a beforeFiles rewrite with locale: false and a has condition matching a query parameter:
async rewrites() {
  return {
    beforeFiles: [
      {
        source: '/:path(.*)',
        has: [
          {
            type: 'query',
            key: 'my-preview-token',
            value: '(?<token>.+)',
          },
        ],
        destination: '/api/my-handler',
        locale: false,
      },
    ],
    afterFiles: [],
    fallback: [],
  }
}
  1. Deploy to Vercel
  2. Make a request with the query parameter: /?my-preview-token=some-value

Current vs. Expected behavior

Expected: The beforeFiles rewrite should match and internally route the request to /api/my-handler.

Current (16.2.0+): The rewrite does not fire. The request passes through to the page handler as if the rewrite doesn't exist. The rewrite config IS present in the build output (verified).

Provide environment information

  • Next.js: 16.2.0 and 16.2.1 (regression)
  • Last working version: 16.1.7
  • Platform: Vercel (deployed)
  • i18n: Pages Router with domain-based routing
  • Build: Turbopack (default)

Which area(s) are affected?

  • Routing (rewrites)
  • Internationalization (i18n)

Verified by bisecting

VersionStatus
16.0.10✅ Works
16.1.0✅ Works
16.1.7✅ Works
16.2.0❌ Broken
16.2.1❌ Broken

Impact

This breaks the Makeswift visual editor integration, which relies on a beforeFiles rewrite with locale: false and has conditions to intercept preview token requests. The @makeswift/next-plugin adds this rewrite automatically. Since 16.2.0, the Makeswift editor cannot load page previews.

Additional context

  • The rewrite config is verified correct in the resolved Next.js config at build time
  • The has condition matches a query parameter (not a header or cookie)
  • The locale: false flag is required because the rewrite destination is an API route
  • Same config works perfectly on 16.1.7 and earlier

extent analysis

TL;DR

  • Downgrade to Next.js version 16.1.7 as a temporary workaround to fix the broken beforeFiles rewrite.

Guidance

  • Verify that the beforeFiles rewrite configuration is correctly applied in the Next.js build output.
  • Check if the query parameter my-preview-token is correctly set in the request.
  • Test the rewrite with a simplified has condition to isolate the issue.
  • Consider opening an issue with Next.js to report the regression and track the fix.

Example

// Simplified has condition for testing
async rewrites() {
  return {
    beforeFiles: [
      {
        source: '/:path(.*)',
        has: [
          {
            type: 'query',
            key: 'my-preview-token',
          },
        ],
        destination: '/api/my-handler',
        locale: false,
      },
    ],
  }
}

Notes

  • The issue is specific to Next.js versions 16.2.0 and 16.2.1, and downgrading to 16.1.7 is a temporary solution.
  • The beforeFiles rewrite with locale: false and has conditions is required for the Makeswift visual editor integration.

Recommendation

  • Apply workaround: Downgrade to Next.js version 16.1.7 until the issue is fixed in a later version.
  • Reason: The downgrade is a temporary solution to restore the correct behavior of the beforeFiles rewrite.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

nextjs - 💡(How to fix) Fix beforeFiles rewrites with locale: false and has conditions stopped firing in 16.2.0 [1 comments, 2 participants]