Skip to content

fix: update queryHash when queryKey is updated using updateOptions #55

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

Merged
merged 2 commits into from
Nov 11, 2021

Conversation

SomaticIT
Copy link
Collaborator

@SomaticIT SomaticIT commented Sep 4, 2021

Hi,

Description

I noticed that when queryKey is updated using the new updateOptions method, the query is not refetched.
This happens because the previous queryHash is not updated.

In this PR, I detect if queryKey is updated and I manually update the queryHash.

Reproduction

<script>
  import { useQuery } from "@sveltestack/svelte-query";

  const query = useQuery(["entities", { search: ""  }], fetchEntities);

  function onSearch(e) {
    query.updateOptions({ queryKey: ["entities", { search: e.target.value }] });
  }
</script>

<input type="text" on:change={onSearch} />

{#if $query.isLoading}
  Loading...
{:else if $query.data}
  {#each $query.data as entity (entity.id)}
    <p>{entity.name}</p>
  {/each}
{/if}

@SomaticIT
Copy link
Collaborator Author

@amen-souissi, any news on this?

@SomaticIT SomaticIT merged commit 2d5de76 into SvelteStack:main Nov 11, 2021
@SomaticIT SomaticIT deleted the @fix/update-query-hash branch November 11, 2021 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant