Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

offline: teardown operations are called immediately on the page reload even if a cache-and-network call is pending #3233

Closed
frederikhors opened this issue May 31, 2023 · 1 comment

Comments

@frederikhors
Copy link
Contributor

frederikhors commented May 31, 2023

After the big work on #3200 there is an issue in how teardown operations are called on the page reload (when there are cached data).

REPRODUCTION: https://codesandbox.io/p/sandbox/issue-urql-6-duplicated-requests-forked-0ybcue.

Steps:

  1. click on "Todos list"

  2. open the browser Dev Tools's console

  3. reload the page

  4. see in the console before, else followed immediately (and not after the fake delay of the backend) before, op.kind === teardown

What I expect

I expect teardown to be called after the backend fake delay response.

More context

I'm using a custom exchange to track pending requests globally:

const pendingRequestsExchange: Exchange = ({ forward }) => {
  function before(op: Operation) {
    if (op.kind === 'subscription') return;
    
    if (op.kind === 'teardown') {
      console.log('before, op.kind === teardown');
      // decrease the global pending requests here
    } else {
      console.log('before, else');
      // increase the global pending requests here
    }
  }
  function after(op: OperationResult) {
    console.log('after()');
    // decrease the global pending requests here
  }
  return (ops$) => {
    const forward$ = pipe(ops$, tap(before));
    return pipe(forward(forward$), tap(after));
  };
};

@kitten said that maybe the issue is my custom exchange and that

you will have to adjust your after call to be more precise. If this is just to keep track of global loading states, I'd suggest to be more accurate with cache-only operations in after and/or maybe adding a delay or debounce here.

but the thing is the after() function of the custom exchange is NEVER called on the first load.

I do not understand why the teardown operation is issued. If this is a cache-and-network call it should wait for the server answer, nope?

Thanks for your work, it's not something I take for granted. Really, thanks.

Gif

issue_teardown

@kitten
Copy link
Member

kitten commented May 31, 2023

This is not a bug, but required for us to issue a new operation:

next(makeOperation('teardown', operation));

@kitten kitten changed the title teardown operations are called immediately on the page reload even if a cache-and-network call is pending offline: teardown operations are called immediately on the page reload even if a cache-and-network call is pending May 31, 2023
@urql-graphql urql-graphql locked and limited conversation to collaborators May 31, 2023
@kitten kitten converted this issue into discussion #3234 May 31, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants