vercel / vercel/next.js

Next/Image SVG with Hash in URL

Open
#56,401 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Image (next/image) not stale
Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

Link to the code that reproduces this issue

https://github.com/ThomasAunvik/next-image-hash-in-svgimage

To Reproduce
  1. Generate SVG Image from https://github.com/jstrieb/github-stats
  2. Attempt use of Next/Image to the generated SVG.
  3. Add #gh-dark-mode-only after the url, as shown point 8 in https://github.com/jstrieb/github-stats#installation
  4. See that the style of the svg is not set
  5. Use a direct img tag, and copy the next/image request url, remove the broken hash, and add to the correct way of hash.

https://github.com/ThomasAunvik/next-image-hash-in-svgimage/blob/fcf8a4fdb8b1508aead04bfa7db1e6162111030b/app/page.tsx#L18-L53

Current vs. Expected behavior

I expected the URL of the request image to include the hash after the nextjs request url.

The result: The hash was url encoded with the image request, making it not apply styling trough the hash.

Verify canary release
  • I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
  Platform: linux
  Arch: x64
  Version: #1 ZEN SMP PREEMPT_DYNAMIC Sat, 23 Sep 2023 22:54:46 +0000
Binaries:
  Node: 20.8.0
  npm: 10.1.0
  Yarn: 1.22.19
  pnpm: N/A
Relevant Packages:
  next: 13.5.5-canary.0
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.1.3
Next.js Config:
  output: N/A
Which area(s) are affected? (Select all that apply)

Image optimization (next/image, next/legacy/image)

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked reproduction at app/page.tsx lines 18-53 and compare the next/image request with the direct img request. Trace the Image Optimization entry point and URL handling for SVG fragments; done means the hash is preserved after the optimized image URL so the SVG styling applies. No test file is named in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, next.js, react
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.