nextjs - 💡(How to fix) Fix preloadEntriesOnStart does not preload middleware [1 comments, 1 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#84380Fetched 2026-04-08 02:19:39
View on GitHub
Comments
1
Participants
1
Timeline
5
Reactions
4
Author
Participants
Timeline (top)
commented ×1issue_type_added ×1labeled ×1mentioned ×1

Fix Action

Fix / Workaround

Now as a workaround we preload middleware manually in instrumentation:

Code Example

__non_webpack_require__(join(process.cwd(), '.next', 'server', 'middleware.js'));

---

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
  Available memory (MB): 4102
  Available CPU cores: 2
Binaries:
  Node: 20.9.0
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: 8.10.2
Relevant Packages:
  next: 15.5.3 // There is a newer version (15.5.4) available, upgrade recommended! 
  eslint-config-next: N/A
  react: 19.1.1
  react-dom: 19.1.1
  typescript: 5.3.3
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/musing-cdn-k5cdjh

To Reproduce

pnpm i && pnpm build && pnpm start in second terminal run curl -w "total: %{time_total}\n" -o /dev/null -s http://localhost:3000 2 times

Current vs. Expected behavior

See that first request is blocked by sync operations in middleware. But they should not occur on first request

<img width="696" height="119" alt="Image" src="https://github.com/user-attachments/assets/3b48025d-daf2-4922-8040-198d086164a6" />

Expected middleware to be preloaded if preloadEntriesOnStart: true. It is enabled by default https://github.com/vercel/next.js/commit/dccff3a82bf7fde4aa893128c93e1e7d68274044

Now as a workaround we preload middleware manually in instrumentation:

__non_webpack_require__(join(process.cwd(), '.next', 'server', 'middleware.js'));

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
  Available memory (MB): 4102
  Available CPU cores: 2
Binaries:
  Node: 20.9.0
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: 8.10.2
Relevant Packages:
  next: 15.5.3 // There is a newer version (15.5.4) available, upgrade recommended! 
  eslint-config-next: N/A
  react: 19.1.1
  react-dom: 19.1.1
  typescript: 5.3.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Middleware

Which stage(s) are affected? (Select all that apply)

Other (Deployed)

Additional context

Screenshot of cpu profile from our app:

Image

Middleware loads only on first request

extent analysis

TL;DR

Upgrade to Next.js version 15.5.4 to potentially resolve the middleware preload issue.

Guidance

  • Verify that the preloadEntriesOnStart option is indeed set to true in the Next.js configuration.
  • Check the release notes for Next.js version 15.5.4 to see if it includes any fixes related to middleware preloading.
  • Test the upgrade by running pnpm install [email protected] and then rebuilding and restarting the application.
  • Monitor the CPU profile and request timings to ensure the middleware is preloading correctly after the upgrade.

Example

No specific code snippet is provided as the issue seems related to a potential version-specific bug in Next.js.

Notes

The provided information suggests a potential issue with middleware preloading in Next.js version 15.5.3. Upgrading to version 15.5.4 may resolve the issue, but it's essential to verify the fix and monitor the application's performance after the upgrade.

Recommendation

Upgrade to fixed version: Upgrade to Next.js version 15.5.4, as it may include fixes for the middleware preloading issue, and the current version has a known workaround that suggests a potential bug.

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