Skip to content

fix: render <Head> tags from dependencies like next-seo - #1440

Merged
vicb merged 4 commits into
opennextjs:mainfrom
mathurshubham:mathurshubham/oss-12-1389-nexthead-from-a-node_modules-dependency-next-seo-is
Nov 25, 2026
Merged

vicb merged 4 commits into
opennextjs:mainfrom
mathurshubham:mathurshubham/oss-12-1389-nexthead-from-a-node_modules-dependency-next-seo-is

Conversation

@mathurshubham

@mathurshubham mathurshubham commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1389

Since Next.js 15.3, pages-router-context skipped remapping *.shared-runtime imports. Dependencies that Next keeps external (e.g. next-seo requiring next/head) then got their own HeadManagerContext, so their <Head> tags were missing from pages rendered by the Worker. In Node, next/dist/server/require-hook.js does this remapping, but the adapter replaces that file with an empty module.

The fix removes the Next.js >= 15.3 early return.

Tests:

  • The spec bundles a fixture through the plugin (Next 14.2 / 15.3 / 16.4). The 15.3 and 16.4 cases fail without the fix.
  • examples/playground15 e2e: /external-head renders <Head> from a file: dependency kept external. The test checks the server HTML and fails without the fix.

…e Pages Router

With Next.js >= 15.3 the adapter stopped remapping `*.shared-runtime`
context imports, assuming Next's webpack aliases them. That holds for app
code but not for Pages Router dependencies kept external in
`node_modules` (e.g. `next-seo`): they load
`next/dist/shared/lib/head.js`, which requires
`./head-manager-context.shared-runtime` and ends up with a second
`HeadManagerContext`, so the `<Head>` tags they render are silently
dropped from the HTML on SSR / ISR renders.

In Node, `next/dist/server/require-hook.js` remaps every request ending in
`.shared-runtime` to `route-modules/pages/vendored/contexts/<name>`. That
hook is shimmed in the Worker, so the esbuild plugin now always does the
same remap and falls back to the original module when there is no
vendored context.

Adds a spec that bundles through the real plugin, and a pages-router e2e
with an injected workspace package rendering `next/head` from
`node_modules`.

Fixes opennextjs#1389
@changeset-bot

changeset-bot Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ed244e9

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

@devin-ai-integration devin-ai-integration Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Note

Newer findings are available below. Devin Review posted a newer report on this PR, in addition to the findings presented here.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

vicb added 2 commits November 25, 2026 18:58
- Only drop the Next.js >= 15.3 early return: every `*.shared-runtime` file Next ships has a vendored context and is requested as `<dir>/<name>.shared-runtime`, so the original matcher handles them.
- Move the e2e test to `examples/playground15`: `examples/e2e` apps are synced from `@opennextjs/aws`.
- Install the test dependency as a `file:` dependency instead of an injected workspace package.
- Simplify comments, the spec and the changeset.
@vicb vicb changed the title fix: remap *.shared-runtime context imports from dependencies in the Pages Router fix: render <Head> tags from dependencies like next-seo Nov 25, 2026
@pkg-pr-new

pkg-pr-new Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

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

commit: ed244e9

@vicb vicb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @mathurshubham for the clear diagnosis and the tests!

I merged the latest main and pushed a follow-up commit:

  • Smaller fix: only the Next.js >= 15.3 early return is removed. Every *.shared-runtime file Next ships (15.5 and 16.4) has a vendored context and is required as <dir>/<name>.shared-runtime, so the original matcher already handles them. The new regex, fallback and pluginData marker are no longer needed.
  • E2E moved to examples/playground15: the examples/e2e apps are synced from @opennextjs/aws and should not be changed here. playground15 already has the /head test for #571.
  • Simpler test dependency: it's now installed as file:./external-head, so we don't need a workspace package, injected, index.d.ts or devDependencies.

Closing #1521 as a duplicate.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Devin Review found 2 new potential issues.

Devin Review

Comment thread examples/playground15/e2e/head.spec.ts Resolved

@vicb vicb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

CI is green 🚀

@vicb
vicb merged commit 873d2b9 into opennextjs:main Nov 25, 2026
14 checks passed
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/head from a dependency (next-seo) is dropped on runtime renders — #571 fix does not cover node_modules

2 participants