Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugs with heuristic to "detect file by whether it has a dot" with trailingSlash #56090

Open
1 task done
taoky opened this issue Sep 27, 2023 · 5 comments
Open
1 task done
Labels
bug Issue was opened via the bug report template. Linking and Navigating Related to Next.js linking (e.g., <Link>) and navigation. not stale A previously `stale` marked issue that is no longer stale.

Comments

@taoky
Copy link

taoky commented Sep 27, 2023

Link to the code that reproduces this issue

https://github.com/taoky-playground/nextjs-remove-trailing-with-dot-bug

To Reproduce

  1. next export yarn build
  2. In exported index.html:
    <div><a href="/a/">a/</a><br/><a href="/b.git">b.git/</a></div>
    While:
    > ls out/
    404/  404.html  _next/  a/  b.git/  favicon.ico  index.html

Current vs. Expected behavior

Current: <a href="/b.git">b.git/</a>

Expected: <a href="/b.git/">b.git/</a>

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 SMP PREEMPT_DYNAMIC Wed, 13 Sep 2023 08:37:40 +0000
Binaries:
  Node: 18.13.0
  npm: 8.19.3
  Yarn: 1.22.19
  pnpm: N/A
Relevant Packages:
  next: 13.5.4-canary.1
  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)

Routing (next/router, next/navigation, next/link)

Additional context

Related (they are all locked):

It is fundamentally broken to "detect file" by checking whether it has a . or not -- this is not a Windows-only world, after all. Although most HTTP server could help redirect to the URL with a trailing slash:

  • It takes an extra HTTP request.
  • This is not fully supported by all servers -- for example, our project is deployed on Cloudflare Pages and unfortunately, it just throws a HTTP 404 in this case.

Thus I believe that

if (/\.[^/]+\/?$/.test(pathname)) {
shall be removed (who will intentionally put a trailing slash after a file?).

@taoky taoky added the bug Issue was opened via the bug report template. label Sep 27, 2023
@github-actions github-actions bot added the Linking and Navigating Related to Next.js linking (e.g., <Link>) and navigation. label Sep 27, 2023
@SukkaW
Copy link
Contributor

SukkaW commented Sep 28, 2023

Hello, the designer/builder of the https://mirrors.help here.

We found out about the issue when we were building the sie. You can also reproduce the error on our site:

  • Open https://mirrors.help/
  • Found the GDB Git in the navigation menu
  • Click the link GDB Git, the address becomes https://help.mirrorz.org/binutils-gdb.git
  • Refresh the page, the https://help.mirrorz.org/binutils-gdb.git becomes 404
  • Only when we manually add / at the end of the address (https://help.mirrorz.org/binutils-gdb.git/) will the page be back

@taoky
Copy link
Author

taoky commented Sep 28, 2023

I have worked out a demo to show this bug:

It also shows that this bug affects router.push(). Source code is at the gh-demo branch: https://github.com/taoky-playground/nextjs-remove-trailing-with-dot-bug/tree/gh-demo

Reproduction:

@taoky
Copy link
Author

taoky commented Sep 28, 2023

Possible related issue at Cloudflare side: cloudflare/workers-sdk#2779

@nextjs-bot
Copy link
Collaborator

This issue has been automatically marked as stale due to two years of inactivity. It will be closed in 7 days unless there’s further input. If you believe this issue is still relevant, please leave a comment or provide updated details. Thank you.

@nextjs-bot nextjs-bot added the stale The issue has not seen recent activity. label Mar 26, 2025
@SukkaW
Copy link
Contributor

SukkaW commented Mar 27, 2025

No the issue is still there, it is not stale.

@nextjs-bot nextjs-bot added not stale A previously `stale` marked issue that is no longer stale. and removed stale The issue has not seen recent activity. labels Mar 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Linking and Navigating Related to Next.js linking (e.g., <Link>) and navigation. not stale A previously `stale` marked issue that is no longer stale.
Projects
None yet
Development

No branches or pull requests

3 participants