Skip to content

Commit

Permalink
(core) - filter network-only requests from the ssrExchange (#2198)
Browse files Browse the repository at this point in the history
* filter network-only requests from the ssrExchange

On the prior lines we defer clearing the data by a microtick which means that the redispatched "network-only" request will also be served from the ssr-cache. We could also opt to defer the redispatch by a microtick but imo it's better to treat network-only requests as bypassing this. Another possible solution would be to check whether we've seen this before as a `revalidation`

* Create strong-islands-hope.md

* formatting
  • Loading branch information
JoviDeCroock authored Jan 21, 2022
1 parent 3c87f66 commit c4a0ede
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/strong-islands-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@urql/core": patch
---

Filter `network-only` requests from the `ssrExchange`, this is to enable `staleWhileRevalidated` queries to successfully dispatch their queries
6 changes: 5 additions & 1 deletion packages/core/src/exchanges/ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ export const ssrExchange = (params?: SSRExchangeParams): SSRExchange => {
// it once, cachedOps$ needs to be merged after forwardedOps$
let cachedOps$ = pipe(
sharedOps$,
filter(operation => !!data[operation.key]),
filter(
operation =>
!!data[operation.key] &&
operation.context.requestPolicy !== 'network-only'
),
map(op => {
const serialized = data[op.key]!;
const result = deserializeResult(op, serialized, includeExtensions);
Expand Down

1 comment on commit c4a0ede

@mikehaertl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JoviDeCroock To me it seems that this change completely breaks network-only policy with SSR:

  • On the server the network-only operations are cached by SSR and thus part of extractData()
  • On the client when the same operation reaches ssr it is neither forwarded (because it's in the data cache) nor added to the result stream (because of your change here)

https://github.com/FormidableLabs/urql/blob/bea39c2eb4a93669f5d1d4ee775dfc45cf56a39d/packages/core/src/exchanges/ssr.ts#L126-L132

This results in an operation that just get's swallowed, i.e. it never emits any result.

Before opening an issue maybe you can explain again why this fix was neccessary. As I'm new to urql I don't get what you mean by "microticks" (I understand wonka + streams, though).

Please sign in to comment.