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

GET request with query params was prerendered #4942

Closed
AlexRMU opened this issue May 16, 2022 · 3 comments
Closed

GET request with query params was prerendered #4942

AlexRMU opened this issue May 16, 2022 · 3 comments

Comments

@AlexRMU
Copy link

AlexRMU commented May 16, 2022

Describe the bug

The response depends on query params, but it was executed once and saved, and then all queries return the result of the first execution.
And why do the endpoints prerendare at all? Isn't this still being worked on?

npm run build -> ./build/prerendered/api/post/get

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-k2ducm

System Info

standart stackblitz and
  System:
    OS: Windows 10 10.0.19044
    CPU: (12) x64 11th Gen Intel(R) Core(TM) i5-11400F @ 2.60GHz
    Memory: 23.18 GB / 31.88 GB
  Binaries:
    Node: 16.15.0 - D:\Program Files\nodejs\node.EXE
    npm: 8.10.0 - D:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0)
    Internet Explorer: 11.0.19041.1566
  npmPackages:
    @sveltejs/adapter-node: ^1.0.0-next.73 => 1.0.0-next.73
    @sveltejs/kit: ^1.0.0-next.330 => 1.0.0-next.330
    svelte: ^3.48.0 => 3.48.0
    vite: ^2.9.9 => 2.9.9

Severity

blocking all usage of SvelteKit

Additional Information

No response

@AlexRMU
Copy link
Author

AlexRMU commented May 16, 2022

The endpoint is in server/entries, but all requests (from load and from the client) go to the prerendered.

@Rich-Harris
Copy link
Member

When you prerender, you're writing files to the filesystem so that a simple webserver can serve them. Query parameters can't exist on the filesystem (both in the literal sense that ? isn't an allowed character on all filesystems, and in the sense that the webserver will ignore them), so if you have a prerendered endpoint called /api/posts/get then it doesn't matter how many times you call it with different parameters, it can only be saved as a file once. The files need to have different paths (/api/posts/[slug]), or it won't work.

If you try to access query parameters in a page during prerendering, SvelteKit will throw an error for those reasons. We need to apply the same logic to endpoints.

And why do the endpoints prerendare at all? Isn't this still being worked on?

Prerendering a page implies prerendering the things the page depends on, otherwise client-side navigation will fail (when you're serving a site from GitHub Pages, navigating from /foo to /bar relies on /bar/__data.json existing, etc). #4093 is about marking endpoints as only being prerenderable, so that we can safely omit them from functions (and so that we have a way of knowing that it's okay for them to use Node built-ins etc) in the case where an app is only partially prerendered. As part of that work we should be able to mark endpoints as never prerenderable, so that even if the pages that depend on them are prerendered (and the data is serialized and inlined into the HTML), requesting the endpoint directly should always invoke a function. I'll close this in favour of #4093.

@AlexRMU
Copy link
Author

AlexRMU commented May 17, 2022

The response of this endpoint for the page is saved in ./prerendered/ and in prerendered html (2 times), and it itself is in ./server/entries/endpoints/. And a prerendered response is returned to all requests to the endpoint, requests do not reach the endpoint itself.
Is it possible to make a prerender so that the endpoint is also available?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants