nextjs - 💡(How to fix) Fix Text fragment stripped from nextjs app [5 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

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#84456Fetched 2026-04-08 02:19:20
View on GitHub
Comments
5
Participants
2
Timeline
11
Reactions
2
Assignees
Timeline (top)
commented ×5mentioned ×2subscribed ×2assigned ×1

Code Example

http://localhost:3000/#:~:text=flask
http://localhost:3001/#:~:text=next
http://localhost:3002/#:~:text=astro

---

Node.js v24.7.0

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:25 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6020
  Available memory (MB): 32768
  Available CPU cores: 12
Binaries:
  Node: 24.7.0
  npm: 11.5.1
  Yarn: 1.22.22
  pnpm: N/A
Relevant Packages:
  next: 15.5.4 // Latest available version is detected (15.5.4).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: export
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/rottabonus/next-text-fragment-repro/tree/main

To Reproduce

  1. Prerequisites: docker
  2. Clone the repo
  3. Build images and start docker-compose stack with docker compose up
  4. Check the application urls
http://localhost:3000/#:~:text=flask
http://localhost:3001/#:~:text=next
http://localhost:3002/#:~:text=astro

Notice that the text-fragment is stripped on the nextjs-application

Current vs. Expected behavior

The text fragment feature is not a standard, but maybe the wicg proposal should be now the expected behaviour: It is recommended that the text fragment be displayed in the location bar’s URL even if a match wasn’t located in the document.

Provide environment information

Node.js v24.7.0

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:25 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6020
  Available memory (MB): 32768
  Available CPU cores: 12
Binaries:
  Node: 24.7.0
  npm: 11.5.1
  Yarn: 1.22.22
  pnpm: N/A
Relevant Packages:
  next: 15.5.4 // Latest available version is detected (15.5.4).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: export

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

Not sure

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

Other (Deployed)

Additional context

This feature works well with multiple different sites, here are some examples

But also are sites where this text is stripped..

extent analysis

TL;DR

The text-fragment feature not working as expected in the Next.js application may be due to the way Next.js handles URL fragments, and a potential workaround could be to modify the Next.js configuration or use a custom solution to preserve the text fragment.

Guidance

  • Review the Next.js documentation and configuration options to see if there's a setting that can be changed to preserve the text fragment in the URL.
  • Investigate the next.config.js file in the provided repository to see if there are any custom configurations that might be causing the issue.
  • Consider using a custom solution, such as a middleware or a plugin, to handle the text fragment and ensure it's preserved in the URL.
  • Compare the behavior of the Next.js application with other sites that have working text-fragment features, such as the examples provided, to identify potential differences in implementation.

Notes

The provided information suggests that the issue might be specific to the Next.js application, and further investigation is needed to determine the root cause. The fact that the text-fragment feature works on other sites, but not on the Next.js application, indicates that there might be a configuration or implementation issue specific to Next.js.

Recommendation

Apply workaround: The recommended approach would be to apply a custom workaround, such as a middleware or a plugin, to handle the text fragment and ensure it's preserved in the URL, as the root cause of the issue is not immediately clear and may require further investigation.

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