Skip to content

fix: place image preload links in <head> instead of <body>#91878

Open
tmoh-figs wants to merge 1 commit intovercel:canaryfrom
tmoh-figs:tmoh/fix-image-preload-srcset
Open

fix: place image preload links in <head> instead of <body>#91878
tmoh-figs wants to merge 1 commit intovercel:canaryfrom
tmoh-figs:tmoh/fix-image-preload-srcset

Conversation

@tmoh-figs
Copy link

@tmoh-figs tmoh-figs commented Mar 24, 2026

Fixes #82254.

React 19 + Next.js 15 incorrectly place image preload links in the <body> rather than the <head> while using the Pages router.

Changes

  • Modified ImagePreload component to use ReactDOM.preload for both App Router and Pages router when available, instead of relying on <Head> component which had placement issues.

Reproducing

The old issue was reproduced in this StackBlitz instance: https://stackblitz.com/edit/stackblitz-starters-evf7wdnm?file=pages/pages-router.tsx

If someone can approve the CI, we can point the stackblitz instance at the preview instance.

@nextjs-bot
Copy link
Collaborator

Allow CI Workflow Run

  • approve CI run for commit: 5a3d045

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

@nextjs-bot
Copy link
Collaborator

nextjs-bot commented Mar 24, 2026

Allow CI Workflow Run

  • approve CI run for commit: 2c7b88a

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

@tmoh-figs tmoh-figs force-pushed the tmoh/fix-image-preload-srcset branch from 5a3d045 to 2c7b88a Compare March 24, 2026 21:50
@tmoh-figs
Copy link
Author

tmoh-figs commented Mar 25, 2026

@naaa760 @ijjk @nehaaprasad This is an updated version of #82263 which was never merged.

@tmoh-figs tmoh-figs marked this pull request as ready for review March 25, 2026 00:13
@tmoh-figs tmoh-figs changed the title fix: handle image preload srcSet correctly fix: place image preload links in <head> instead of <body> Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

<img /> elements rendered by the Pages Router cause <link rel="preload"> tags to be added to the body unexpectedly

2 participants