nextjs - 💡(How to fix) Fix Image src that includes more than 1 query param results in broken output [9 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

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#84402Fetched 2026-04-08 02:19:31
View on GitHub
Comments
9
Participants
3
Timeline
20
Reactions
1
Timeline (top)
commented ×9mentioned ×4subscribed ×4labeled ×2

Code Example

<link rel="preload" href="https://picsum.photos/id/870/200/300?grayscale=1&amp;blur=2" as="image"/>
<div>
  <img src="https://picsum.photos/id/870/200/300?grayscale&amp;blur=2">
</div>

---

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.6.0-canary.38 // Latest available version is detected (15.6.0-canary.38).
  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/sandbox/reverent-http-v2ycvz

To Reproduce

  1. Start the sandbox
  2. Inspect the html in the network monitor

Current vs. Expected behavior

Attribute that contains an url with more than 1 query param results in broken encoded output. Browsers seem able to recover from this mistake and fetch the correct url, but crawlers etc do not.

<link rel="preload" href="https://picsum.photos/id/870/200/300?grayscale=1&amp;blur=2" as="image"/>
<div>
  <img src="https://picsum.photos/id/870/200/300?grayscale&amp;blur=2">
</div>

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.6.0-canary.38 // Latest available version is detected (15.6.0-canary.38).
  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)

Output, Image (next/image)

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

next build (local), Vercel (Deployed), next dev (local), next start (local), Other (Deployed)

Additional context

No response

extent analysis

TL;DR

The issue can be fixed by properly encoding URLs with multiple query parameters in the href attribute of the link tag.

Guidance

  • Verify that the href attribute is correctly encoded by checking the HTML output in the network monitor.
  • Check the Next.js configuration to ensure that URL encoding is properly handled.
  • Consider using a library or function to encode URLs with multiple query parameters, such as encodeURIComponent() in JavaScript.
  • Inspect the next/image component to see if it has any options for handling URL encoding.

Example

<link rel="preload" href="https://picsum.photos/id/870/200/300?grayscale=1&blur=2" as="image"/>

can be replaced with

const encodedUrl = encodeURIComponent('https://picsum.photos/id/870/200/300?grayscale=1&blur=2');
// use encodedUrl in the href attribute

Notes

The issue seems to be related to the encoding of URLs with multiple query parameters. The provided code snippet shows that the href attribute is not properly encoded, which can cause issues with crawlers and other non-browser clients.

Recommendation

Apply workaround: Use a library or function to encode URLs with multiple query parameters, such as encodeURIComponent() in JavaScript, to ensure that the href attribute is correctly encoded.

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

nextjs - 💡(How to fix) Fix Image src that includes more than 1 query param results in broken output [9 comments, 3 participants]