vercel / vercel/next.js

Relative <img> 404s when using next/link and trailingSlash in Safari

Open
#65,009 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug linear: next
Dominant language
JavaScript
Stars
142k
Forks
32.5k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

Link to the code that reproduces this issue

https://github.com/blakewilson/relative-img-path-bug

To Reproduce
  1. Start the application in dev mode
  2. Go to http://localhost:3000
  3. Click the first link and confirm that the image exists on the /hello-world route
  4. Go back to http://localhost:3000
  5. Click the second link (using next/link) and notice the image 404s on the /hello-world route. Refresh the page, and notice the image appears.
Current vs. Expected behavior

Following the steps above, I expect to see the correct image when rendering the hello world route via next/link. Instead, the image 404s.

Provide environment information
Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 23.2.0: Wed Nov 15 21:54:51 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6030
  Available memory (MB): 18432
  Available CPU cores: 11
Binaries:
  Node: 18.17.0
  npm: 10.2.5
  Yarn: N/A
  pnpm: 8.15.1
Relevant Packages:
  next: 14.3.0-canary.21 // Latest available version is detected (14.3.0-canary.21).
  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)

Not sure

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

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

Additional context

No response

NEXT-3245

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 repository and follow the listed steps in Safari, comparing the normal link with next/link while trailingSlash is enabled. Trace the navigation and image request for /hello-world, then verify that the image loads without a refresh; the issue also references Linear ticket NEXT-3245 for existing context.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nextjs, react
Domain
frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.