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

adapter-node responds with pre-rendered assets for non-GET requests #3294

Closed
moatra opened this issue Jan 12, 2022 · 2 comments
Closed

adapter-node responds with pre-rendered assets for non-GET requests #3294

moatra opened this issue Jan 12, 2022 · 2 comments
Labels
p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. pkg:adapter-node
Milestone

Comments

@moatra
Copy link
Contributor

moatra commented Jan 12, 2022

Describe the bug

Given the following scenario:

  • Using @sveltejs/adapter-node (ver ^1.0.0-next.61)
  • Enabled export const prerender = true; on a page
  • Have a POST endpoint handler on the same path as the pre-rendered page

The artifact produced by the node adapter will always respond with the prerendered page to any requests to the shared path, even if the request uses method POST.

Reproduction

  1. Clone https://github.com/moatra/svelte-prerender-bug
  2. npm install
  3. npm run dev
    • Navigate to the /login page with javascript enabled, and use foo@example.com and bar.
    • Note the successful response with content-type application/json -> The request was served by the endpoint handler.
  4. Kill the dev process
  5. npm run build
  6. node build
    • Navigate to the /login page with javascript enabled
    • Open developer console
    • Submit the login page using foo@example.com and bar
    • Note the "unexpected character at line 1 column 1 of the JSON data" error -> The request was served with the pre-rendered component.

Logs

No response

System Info

❯ npx envinfo --system --binaries --browsers --npmPackages "{svelte,@sveltejs/*,vite}"

  System:
    OS: Linux 5.15 Fedora Linux 35 (Workstation Edition)
    CPU: (16) x64 AMD Ryzen 7 3700X 8-Core Processor
    Memory: 3.43 GB / 31.08 GB
    Container: Yes
    Shell: 5.1.8 - /bin/bash
  Binaries:
    Node: 16.13.0 - /usr/bin/node
    npm: 8.1.0 - /usr/bin/npm
  Browsers:
    Firefox: 95.0.2
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.10 
    @sveltejs/adapter-node: ^1.0.0-next.61 => 1.0.0-next.61 
    @sveltejs/kit: next => 1.0.0-next.225 
    svelte: ^3.44.0 => 3.46.0 

Severity

blocking an upgrade

Additional Information

The obvious workaround is to disable pre-rendering, but this meets the current suggested guidelines for when to enable pre-rendering.

When GET-ing the page, every user should receive the same response. It's only once a POST request is made with fallthrough logic that the response should be varied.

@moatra moatra changed the title node-adapter responds with pre-rendered assets for non-GET requests adapter-node responds with pre-rendered assets for non-GET requests Jan 12, 2022
@benmccann
Copy link
Member

The prerendered pages are served here:

serve(path.join(__dirname, '/prerendered'), 0),

@lukeed it sounds like sirv is responding to POST requests?

@benmccann benmccann added p3-edge-case SvelteKit cannot be used in an uncommon way p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. and removed p3-edge-case SvelteKit cannot be used in an uncommon way labels Jan 12, 2022
@Rich-Harris Rich-Harris added this to the 1.0 milestone May 16, 2022
@dummdidumm
Copy link
Member

Since #4252 was implemented this is no longer possible, therefore closing this.

@dummdidumm dummdidumm closed this as not planned Won't fix, can't repro, duplicate, stale Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. pkg:adapter-node
Projects
None yet
Development

No branches or pull requests

4 participants