Repository navigation
fix: render <Head> tags from dependencies like next-seo - #1440
Merged
Conversation
…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 detectedLatest commit: ed244e9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
# Conflicts: # pnpm-lock.yaml
- 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.
*.shared-runtime context imports from dependencies in the Pages Router<Head> tags from dependencies like next-seo
commit: |
vicb
reviewed
Nov 25, 2026
vicb
left a comment
Contributor
There was a problem hiding this comment.
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-runtimefile 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 andpluginDatamarker are no longer needed. - E2E moved to
examples/playground15: theexamples/e2eapps are synced from@opennextjs/awsand should not be changed here. playground15 already has the/headtest for #571. - Simpler test dependency: it's now installed as
file:./external-head, so we don't need a workspace package,injected,index.d.tsor devDependencies.
Closing #1521 as a duplicate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1389
Since Next.js 15.3,
pages-router-contextskipped remapping*.shared-runtimeimports. Dependencies that Next keeps external (e.g.next-seorequiringnext/head) then got their ownHeadManagerContext, so their<Head>tags were missing from pages rendered by the Worker. In Node,next/dist/server/require-hook.jsdoes this remapping, but the adapter replaces that file with an empty module.The fix removes the Next.js >= 15.3 early return.
Tests:
examples/playground15e2e:/external-headrenders<Head>from afile:dependency kept external. The test checks the server HTML and fails without the fix.