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

Path prefix does not work when page URL starts with path prefix #27604

Closed
panupetteri opened this issue Oct 22, 2020 · 11 comments
Closed

Path prefix does not work when page URL starts with path prefix #27604

panupetteri opened this issue Oct 22, 2020 · 11 comments
Labels
stale? Issue that may be closed soon due to the original author not responding any more. topic: core Relates to Gatsby's core (e.g. page loading, reporter, state machine) type: bug An issue or pull request relating to a bug in Gatsby

Comments

@panupetteri
Copy link

Description

Path prefix (https://www.gatsbyjs.com/docs/path-prefix/) does not work when page URL starts with path prefix. For example, if path prefix is /blog and page's URL is blog, navigating to /blog/blog does not work.

This can be demonstrated in:

https://gatsby-path-prefix-bug.netlify.app/blog/blog/

(page works with Javascript disabled, but not with Javascript enabled)

Working example of path prefix can be found in:

https://gatsby-path-prefix-bug.netlify.app/blog/

Steps to reproduce

  1. npx gatsby new gatsby-path-prefix-bug https://github.com/gatsbyjs/gatsby-starter-hello-world
  2. cd gatsby-path-prefix-bug
  3. cp src/pages/index.js src/pages/blog.js
  4. Edit gatsby-config.js to contain module.exports = { pathPrefix: "/blog" }
  5. npx gatsby build --prefix-paths && npx gatsby serve --prefix-paths
  6. Open http://localhost:9000/blog/blog

Expected result

"Hello world!" text should be seen

Actual result

"Hello world!" text is seen for a while and then a blank page is seen

Environment

System:
OS: Windows 10 10.0.19041
CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
Binaries:
Node: 12.16.3 - C:\Program Files\nodejs\node.EXE
npm: 6.14.5 - C:\Program Files\nodejs\npm.CMD
Languages:
Python: 3.8.3 - C:\Python38\python.EXE
Browsers:
Chrome: 86.0.4240.75
Edge: Spartan (44.19041.423.0), Chromium (86.0.622.48)
npmPackages:
gatsby: ^2.24.79 => 2.24.79

@panupetteri panupetteri added the type: bug An issue or pull request relating to a bug in Gatsby label Oct 22, 2020
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Oct 22, 2020
@im-adithya
Copy link
Contributor

im-adithya commented Oct 22, 2020

I am interested. Can anyone help me regarding this?

@ascorbic
Copy link
Contributor

Thanks for the detailed report. This seems to be because we're calling trimPathname more than once on a path. Looking at the network tab, it's requesting page data from index instead of /blog/. @im-adithya if you feel up to it, the relevant code is in packages/gatsby/cache-dir/find-path.js. You'd need to work out where it's being called and why it's being called more than once. You'll find details here on how to get set up. https://www.gatsbyjs.com/contributing/code-contributions/

@ascorbic ascorbic added topic: core Relates to Gatsby's core (e.g. page loading, reporter, state machine) topic: reach/router and Links labels Oct 22, 2020
@im-adithya
Copy link
Contributor

@ascorbic Thank you so much!! I'll try my best to fix this!

@ascorbic ascorbic removed the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Oct 22, 2020
@im-adithya
Copy link
Contributor

@ascorbic seems like I've found the bug can you please review it 😃

@github-actions
Copy link

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here.
If we missed this issue or if you want to keep it open, please reply here.
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 💪💜

@github-actions github-actions bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Nov 13, 2020
@panupetteri
Copy link
Author

Hi,

thanks a lot of updates @ascorbic, @im-adithya and @Kumail786, we appreciate it! We are still having this issue on our end and it stops us from progressing. So the issue is not stale.

Any updates on when this could be fixed? So far, I see one commit (Kumail786@4c05192) and one pull request (#27621) addressing this, but the pull request has broken tests.

@github-actions github-actions bot removed the stale? Issue that may be closed soon due to the original author not responding any more. label Nov 17, 2020
@github-actions
Copy link

github-actions bot commented Dec 7, 2020

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here.
If we missed this issue or if you want to keep it open, please reply here.
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 💪💜

@github-actions github-actions bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Dec 7, 2020
@github-actions
Copy link

Hey again!

It’s been 60 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it.
Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY. Please feel free to comment on this issue or create a new one if you need anything else.
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks again for being part of the Gatsby community! 💪💜

@koxu1996
Copy link

I stumbled upon this and spend few hours investigating problem. Let's analyze this bug for my case:

  1. Here findPath('/blog/blog/here-be-dragons') is called, which calls trimPathname underneath:

    const realPath = findPath(pagePath)

    Return value: /blog/here-be-dragons

  2. Then doPrefetch('/blog/here-be-dragons') is called:

    this.doPrefetch(realPath).then(() => {

  3. Then loadPageDataJson('/blog/here-be-dragons') is called, which calls findPath (and trimPath underneath) again:

    const pagePath = findPath(rawPath)

As a result /blog is trimmed twice and we get /here-be-dragons URL, therefore 404 errors.

@danielmiksavmlyr
Copy link

danielmiksavmlyr commented Nov 18, 2024

Hi there... It has been 3 years since this BUG was recently commented and it is still not fixed. I have exactly the same problem... I think I know what is the root cause... In loadPage method

loadPage(rawPath) {

you call findPath which internally strip the path prefix once. Lower in the same method you call loadPageDataJson passing already trimmed path (pagePath) and as internally loadPageDataJson call findPath again, then path prefix gets double stripped.

Unfortunately it looks like that this issue is even more complex. Similar duplication still exists in doPrefetch logic as @koxu1996 mentioned above.

@danielmiksavmlyr
Copy link

danielmiksavmlyr commented Nov 19, 2024

@sidharthachatterjee, @wardpeet I see that you were involved in loader.js (eg. #17412, #25723) module contribution so I assume you have a lot of knowledge on how it works or suppose to work... Unfortunately as I mentioned in my previous comment I see that this very use case has never been considered during implementation... The best idea I have as for now is making sure that findPath is always called on rawPath... So far I discovered that in many use cases findPath is called twice or even more in the way that the outcome from previous call is passed as argument in the next call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale? Issue that may be closed soon due to the original author not responding any more. topic: core Relates to Gatsby's core (e.g. page loading, reporter, state machine) type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

No branches or pull requests

5 participants