Next v13.4.5 - basePath prepended TWICE in the Network Request, yet <Link href> URL it exists once
Unanswered
Black-capped Vireo posted this in #help-forum
Black-capped VireoOP
Hi all,
Recently have been testing on Next
Have run into an odd scenario where some of the links when navigating result in having the
Here's what's being observed:
Generated HTML:
...☝️ Click the link 🔗
Generated Request (DevTools > Network):
Request URL:
...
Something to note: When observing the initiator for the request, there is an apparent
Also, worth noting that while the app is configured for static export, the behavior is reproducible in both development mode and production builds.
❓ Has anyone run into this before? I did some searching and found some older bugs around basePath duplication specific to presence of query params, but the links in question do not contain URL arguments FWIW.
Recently have been testing on Next
v13.4.4 and v13.4.5 an application using Pages Router, configured with output: 'export' and an established basePath: '/subdir'Have run into an odd scenario where some of the links when navigating result in having the
basePath duplicated (added twice) -- the interesting thing is that the URL href (generated HTML) do not exhibit this duplication! However, upon clicking a <Link>, the actual network request contains the basePath multiple times, resulting in a routing error.Here's what's being observed:
Generated HTML:
<a href="/subdir/path/to/example">Example</a>...☝️ Click the link 🔗
Generated Request (DevTools > Network):
Request URL:
https://domain.com/subdir/subdir/path/to/example...
basePath is duplicated.Something to note: When observing the initiator for the request, there is an apparent
onClick handler, presumably native to <Link>. You can see in the attached image there are actually two (2)click event handlers div#__next associated with the link. Interestingly, if the handler denoting useCapture: false is manually removed, the basePath duplication goes away! 🤔 Also, worth noting that while the app is configured for static export, the behavior is reproducible in both development mode and production builds.
❓ Has anyone run into this before? I did some searching and found some older bugs around basePath duplication specific to presence of query params, but the links in question do not contain URL arguments FWIW.
5 Replies
Black-capped VireoOP
Also, forgot to mention that if you CMD (or SHIFT) + Click the link to open in new tab / window, the behavior works as expected (again, generated HTML
Something in the routing /
href URL is correct!)Something in the routing /
Link internal click handling seems to be duplicating the basePath such that the URL that is ultimately requested does NOT match the URL of the generated <a href>Black-capped VireoOP
In case this is helpful context, moving away from SSG (
output: 'export') to instead use output: 'standalone' unfortunately did not prevent this issue from happening. It is still reproducible even when SSR support is enabled, including during local development, FWIW.@Black-capped Vireo do you have a minimal reproduction of this bug? it might be helpful to create an issue in https://github.com/vercel/next.js/issues so they can fix it
Black-capped VireoOP
Not yet, but I completely agree! I will see if I can simplify and get it filed.
Oddly, it's not happening 100% of the time, so I want to be extra sure it's not something erroneous in the current approach, even though it's all pretty straightforward on the surface ðŸ‘
Oddly, it's not happening 100% of the time, so I want to be extra sure it's not something erroneous in the current approach, even though it's all pretty straightforward on the surface ðŸ‘
Asiatic Lion
Hi @Black-capped Vireo , Were you able to find any workaround - will appreciate if you could share how you moved ahead.