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

bug(gatsby-plugin-fastify): Error fetching page data for /using-ssr when pagePrefix is set #458

Closed
syckki opened this issue Dec 10, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@syckki
Copy link

syckki commented Dec 10, 2023

The error happens when I use pathPrefix (e.g: /gatsby) in gatsby-config.js. I am serving SSR pages.

ERROR: Error processing /gatsby/page-data/using-ssr/page-data.json, Error fetching page data for /using-ssr: Page for "/gatsby/page-data/using-ssr/page-data.json" not found

To Reproduce

Steps to reproduce the behavior:

  1. Run the following boilerplate npx gatsby new gatsby-starter-rendering-modes
  2. Add the following packagesnpm install gatsby-plugin-fastify fastify
  3. Set pathPrefix (e.g: /gatsby) in gatsby-config.js
  4. Add the plugin plugins: [ { resolve: 'gatsby-plugin-fastify' }] in gatsby-config.js,
  5. Add the script { "scripts": { "start": "gserve" } } in package.json
  6. Run the command npm run start
  7. The error appears in Console Tab
image

A quick search in the gatsby-plugin-fastify code reveals me, the reason of the error.

Use potentialPagePath instead of workingURL variable as pathName param in the getData method.
image

[Additionally to solve problem with trailingSlash]
Use path instead of workingURL variable as param of reverseFixedPagePath method.
image

Expected behavior

A quick change in the compiled code solves the problem.

Code line 56 is modified to use the variable potentialPagePath.
image

[Additionally to solve problem with trailingSlash]
Code line 93 is modified to use the variable path.
image

eureka!!!

image

System Info

  • After running the command: yarn gatsby info --clipboard in my project directory

    System:
    OS: Windows 11 10.0.22621
    CPU: (4) x64 Apple Silicon
    Binaries:
    Node: 19.9.0 - C:\Users\JHONNY1\AppData\Local\Temp\xfs-fea441dd\node.CMD
    Yarn: 4.0.2 - C:\Users\JHONNY
    1\AppData\Local\Temp\xfs-fea441dd\yarn.CMD
    npm: 9.6.3 - C:\Program Files\nodejs\npm.CMD
    Languages:
    Python: 3.12.0
    Browsers:
    Edge: Chromium (119.0.2151.97)
    npmPackages:
    gatsby: 5.12.12 => 5.12.12
    gatsby-plugin-alias-imports: 1.0.5 => 1.0.5
    gatsby-plugin-fastify: 0.13.1 => 0.13.1
    gatsby-plugin-federation: 2.5.0 => 2.5.0
    gatsby-plugin-image: 3.12.3 => 3.12.3
    gatsby-plugin-manifest: 5.12.3 => 5.12.3
    gatsby-plugin-offline: 6.12.3 => 6.12.3
    gatsby-plugin-preconnect: 1.4.0 => 1.4.0
    gatsby-plugin-robots-txt: 1.8.0 => 1.8.0
    gatsby-plugin-sharp: 5.12.3 => 5.12.3
    gatsby-plugin-sitemap: 6.12.3 => 6.12.3
    gatsby-plugin-styled-components: 6.12.0 => 6.12.0
    gatsby-source-filesystem: 5.12.1 => 5.12.1
    gatsby-transformer-sharp: 5.12.3 => 5.12.3

@syckki syckki added the bug Something isn't working label Dec 10, 2023
@moonmeister
Copy link
Contributor

This fix seems incorrect to me...those assets should still be served from /gatsby. Are you following the Gatsby Docs and correctly running the build with gatsby build --prefix-paths?

@syckki
Copy link
Author

syckki commented Dec 11, 2023

@moonmeister

Yes, I did!

I am using gatsby build --prefix-paths in order to build with prefixPath. Right now I am serving my app with that configuration and with that minimal change. I would appreciate to you that you can reproduce my issue following my instrucction.

Include the gatsby build --prefix-paths in the script, since I omite mentioned it before.

Note: in fact gatsby serve --prefix-paths has problems using SSR. And your plugin is better than gatsby serve

@moonmeister
Copy link
Contributor

The many problems with gatsby serve are why this plugin exists.

Okay, I'll try to find some time to look at this.

From my current understanding your current solution shouldn't be correct, the assumption is...if you have a prefix, the non-prefixed path is probably an entirely different server and thus wouldn't be able to handle these routes.

@moonmeister
Copy link
Contributor

Okay, confirmed. I understand what's happening. potentialPagePath seems like the correct move since we already have that. I'm happy to merge a PR on this if you can get that submitted.

@syckki
Copy link
Author

syckki commented Dec 25, 2023

Thank you for the confirmation! I agree with proceeding with "potentialPagePath". I plan to submit the Pull Request, but I'll do so after the Christmas holidays. I hope you have a wonderful holiday season with your loved ones as well. 🎄☃️

@moonmeister
Copy link
Contributor

Deprecating Package. See: #495 for more info.

@moonmeister moonmeister closed this as not planned Won't fix, can't repro, duplicate, stale Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants