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

useTransactionQuery cache & query issue with variables #1162

Open
bkniffler opened this issue Oct 7, 2022 · 5 comments · Fixed by #1163
Open

useTransactionQuery cache & query issue with variables #1162

bkniffler opened this issue Oct 7, 2022 · 5 comments · Fixed by #1163
Labels
help wanted Extra attention is needed

Comments

@bkniffler
Copy link
Contributor

bkniffler commented Oct 7, 2022

Using a very simple query, useTransactionQuery seems to lag behind with the results if variables change in some cases. In this example, we have a variable that filters a list. It can be either a or b.

Initially, the button will say Toggle b, because letter is a. The query result is correct, a list filtered by a. Clicking the button will change letter to b. Results change as expected, everything starting with b is shown. Clicking again will switch letter back to a, but now the results will remain to the b list. Clicking further, the results will always be the ones from the previous variables.

Hope this makes sense

Bildschirmaufnahme.2022-10-07.um.14.27.06.mov
 const [letter, setLetter] = useState('a');
 const x = useTransactionQuery(
    (x, { letter }) =>
      x
        .app({ where: { name: { _ilike: `${a}%` } } })
        .map((x) => ({ id: x.id, name: x.name })),
    {
      variables: {
        letter,
      },
    }
  );

  return (
    <ul>
      <button onClick={() => setLetter(letter === 'a' ? 'b' : 'a')}>
        Toggle {letter === 'a' ? 'b' : 'a'}
      </button>
      {x.data?.map((app) => (
        <li key={app.id}>{app.name}</li>
      ))}
    </ul>
  );
@bkniffler
Copy link
Contributor Author

Adding this seems to solve the issue

      fetchPolicy: 'cache-and-network',

@bkniffler
Copy link
Contributor Author

bkniffler commented Oct 7, 2022

Still seeing issues. Extending this to more letters (a, b, e, g), I'm seeing issues on the first fetches for each letter. Subsequent fetches work good as seen on the video.

Bildschirmaufnahme.2022-10-07.um.15.05.14.mov

@bkniffler
Copy link
Contributor Author

@vasyas
Copy link

vasyas commented Nov 30, 2022

With the PR applied, still get the error with fetchPolicy: 'cache-first'.
With fetchPolicy: 'cache-and-network' it works.

@vicary vicary added the help wanted Extra attention is needed label Dec 1, 2022
@vicary
Copy link
Member

vicary commented Dec 1, 2022

I will eventually get here but my list is long right now.

@bkniffler Would you like to work on this?

@vicary vicary reopened this Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants