question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Post request via fetch gets overriden/replaced in `load()`

See original GitHub issue

Describe the bug Two parallel (?) fetch POST requests (one from $layout.svelte, and one from index.svelte) with different contents end up having the same response on the client side.

Logs nothing interesting happening in the logs

To Reproduce I set up a repro repository here https://github.com/neesh-studio/sk-fetch-override-repro which loads two festival objects from a graphQL api. One Festival is called “First Festival”, the other “Another Festival”.

The SSR implementation seems to work as there is a short flash of the “Another Festival” title on page refresh. But it get’s replaced on the client with “First Festival”. What i get to see: grafik

Expected behavior what I expect to see: grafik

I expect the fetch api to work the same on server and client and the client not overriding another (POST) request. (A quick test shows the behaviour seems fine for GET requests)

The problem goes away if I uncomment line 21 in api.ts

  if (typeof window !== "undefined") fetchApi = fetch;

Information about your SvelteKit Installation:

  • The output of npx envinfo --system --npmPackages svelte,@sveltejs/kit --binaries --browsers
System:
    OS: Linux 5.4 Ubuntu 20.04.2 LTS (Focal Fossa)
    CPU: (4) x64 Intel(R) Core(TM) i5-3320M CPU @ 2.60GHz
    Memory: 10.16 GB / 12.35 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 14.15.5 - ~/.nvm/versions/node/v14.15.5/bin/node
    npm: 6.14.11 - ~/.nvm/versions/node/v14.15.5/bin/npm
  npmPackages:
    @sveltejs/kit: next => 1.0.0-next.58 
    svelte: ^3.29.0 => 3.35.0 
  • Your browser Chrome: Version 89.0.4389.90 (64-Bit)

  • Your adapter (e.g. Node, static, Vercel, Begin, etc…) dev server

Severity Minor, there is a workaround (as described) but I wanted to post the issue early in case this is somehow connected to #591

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
Conduitrycommented, Apr 2, 2021

In any case, I don’t think it’s safe to assume that two requests with different POST bodies would have the same response anyway, even if they happened to be JSON encodings of equivalent objects. That sounds like a place we don’t want to go.

1reaction
Rich-Harriscommented, Apr 2, 2021

Possibly… though I don’t think there’s a good reason anyone would have for POSTing to anything that wasn’t a GraphQL endpoint in load

Read more comments on GitHub >

github_iconTop Results From Across the Web

Overriding .fetch() works with fake data, errors with urlRoot ...
I've bound a model to a view, and if I override .fetch() and fake the response, everything works (I can update the model...
Read more >
Intercepting JavaScript Fetch API requests and responses
The code above overrides the original Fetch method with a custom implementation and calls the original Fetch method inside it. You'll use this ......
Read more >
Fetch Standard
At a high level, fetching a resource is a fairly simple operation. A request goes in, a response comes out. The details of...
Read more >
ASP.NET Core Razor component lifecycle | Microsoft Learn
In the FetchData component of the Blazor templates, OnInitializedAsync is overridden to asynchronously receive forecast data ( forecasts ).
Read more >
chrome.webRequest - Chrome Developers
Internally, one URL request can be split into several HTTP requests (for ... To make sure the behavior change goes through, call handlerBehaviorChanged()...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found