Skip to content

fix(patches): include prefetch-hints.json in loadManifest glob for Next.js 16.2#1160

Merged
petebacondarwin merged 2 commits intoopennextjs:mainfrom
matthewvolk:fix/prefetch-hints-manifest
Mar 23, 2026
Merged

fix(patches): include prefetch-hints.json in loadManifest glob for Next.js 16.2#1160
petebacondarwin merged 2 commits intoopennextjs:mainfrom
matthewvolk:fix/prefetch-hints-manifest

Conversation

@matthewvolk
Copy link
Copy Markdown
Contributor

@matthewvolk matthewvolk commented Mar 20, 2026

Problem

Next.js 16.2.0 introduced prefetch-hints.json, a new server manifest loaded unconditionally by NextNodeServer.getPrefetchHints(). The file exists in .next/server/ and is listed in required-server-files.json, but the glob pattern in load-manifest.ts only matches *-manifest.json and required-server-files.json — so no if/else branch is generated for it and the patched loadManifest() throws at runtime:

Unexpected loadManifest(/.next/server/prefetch-hints.json) call!

Why this is needed alongside #1151

PR #1151 adds graceful return {} fallbacks for optional manifests — ones Next.js loads with handleMissing: true (e.g. subresource-integrity-manifest.json, react-loadable-manifest.json). Those files may or may not exist at build time, and Next.js handles missing responses gracefully.

prefetch-hints.json is different: it is a required manifest that always exists in the build output and is loaded without handleMissing: true. It simply doesn't match the *-manifest.json glob pattern because its filename doesn't end with -manifest. The correct fix is to include it in the glob so its contents are inlined at build time, not to return an empty object at runtime.

Note: This fix alone is not sufficient for full Next.js 16.2.0 support on Workers. It also requires #1151 (optional manifest fallbacks) and a fix for extensionless manifest paths — some manifests like dynamic-css-manifest and subresource-integrity-manifest are requested without the .json extension, which causes the current $PATH.endsWith(...) checks to miss them (see comment on #1151).

Fix

Add prefetch-hints to the existing glob alternation in load-manifest.ts. This follows the same pattern used when required-server-files was added to the glob. Backwards compatible with Next.js 15/16.1.x where the file doesn't exist (glob simply finds no match).

Fixes #1157. Related: #1141, #1151.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 20, 2026

🦋 Changeset detected

Latest commit: 8dfcca3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@opennextjs/cloudflare Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 21, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@opennextjs/cloudflare@1160

commit: 8dfcca3

Copy link
Copy Markdown
Collaborator

@conico974 conico974 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the fix, could you just fix the prettier check please ?

HazemKhaled added a commit to HazemKhaled/evisa that referenced this pull request Mar 21, 2026
Copy link
Copy Markdown
Collaborator

@sommeeeer sommeeeer left a comment

Choose a reason for hiding this comment

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

LGTM

@matthewvolk matthewvolk force-pushed the fix/prefetch-hints-manifest branch from bfef748 to 8dfcca3 Compare March 23, 2026 17:38
@matthewvolk
Copy link
Copy Markdown
Contributor Author

Thanks @conico974 and @sommeeeer for the quick review! I just pushed a fix for formatting. It looks like I don't have permissions to merge this PR on my end. Y'all mind pressing "Squash & Merge" for me (or whatever merge option you prefer)?

@petebacondarwin petebacondarwin merged commit 161e726 into opennextjs:main Mar 23, 2026
7 checks passed
ColeMurray pushed a commit to ColeMurray/background-agents that referenced this pull request Apr 20, 2026
## Summary
- bump `@opennextjs/cloudflare` from `1.17.1` to `1.19.1` and pin the
version in `packages/web/package.json`
- pick up the OpenNext Cloudflare fixes for the Next.js 16.2
`prefetch-hints.json` runtime crash I hit during deployment after
updating to the latest version of open-inspect
- keep Open-Inspect users on a known-good adapter version via the repo
lockfile instead of relying on whatever version `npx` might otherwise
fetch

## Why
I hit a production failure after deploying the Cloudflare web app with
Next `16.2.3`:

```text
Error 1101
Unexpected loadManifest(/.next/server/prefetch-hints.json) call!
```

Root cause: Next 16.2 introduced `prefetch-hints.json`, but
`@opennextjs/cloudflare@1.17.1` did not inline or gracefully handle that
manifest in its patched `loadManifest()` runtime shim.

Upstream references:
- opennextjs/opennextjs-cloudflare#1157
- opennextjs/opennextjs-cloudflare#1160
- opennextjs/opennextjs-cloudflare#1151

`1.19.1` includes the manifest-handling fixes released after `1.17.1`,
so this avoids the Cloudflare worker startup crash without keeping our
app pinned to an older Next version.

## Validation
- verified locally that the failure reproduces with `next@16.2.3` +
`@opennextjs/cloudflare@1.17.1`
- verified a minimal standalone repro serves successfully after
upgrading the adapter to `@opennextjs/cloudflare@1.17.3+`

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Chores**
* Updated development dependency version for improved build tooling
compatibility.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Next.js 16.2.0 crashes on Cloudflare Workers (Error 1101): Unexpected loadManifest(/.next/server/prefetch-hints.json) call!

4 participants