Skip to content

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

@moatra

Description

@moatra

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 [email protected] 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 [email protected] 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    p1-importantSvelteKit cannot be used by a large number of people, basic functionality is missing, etc.pkg:adapter-node

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions