Skip to content

Commit

Permalink
Fix error when unsubscribing from cache between fetch and render (#548)
Browse files Browse the repository at this point in the history
* test to reproduce reported error

* subscribing to the store should always subscribe to the cache

* integration tests pass

* changeset
  • Loading branch information
AlecAivazis authored Sep 17, 2022
1 parent e02e524 commit cd00b5f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/tidy-foxes-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'houdini': patch
---

Fix bug when unsubscribing between load and render
19 changes: 8 additions & 11 deletions integration/src/routes/stores/mutation-update/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
<script lang="ts">
import { GQL_UpdateUser, graphql, MutationUpdateUsersListStore } from '$houdini';
import { GQL_UpdateUser, graphql } from '$houdini';
import { stry } from '@kitql/helper';
import type { PageData } from './$types';
const usersList: MutationUpdateUsersListStore = graphql`
query MutationUpdateUsersList {
usersList(limit: 5, snapshot: "update-user-mutation") {
id
name
...UserInfo
}
}
`;
export let data: PageData;
// leave this awkward pattern to make sure this doesn't come back: https://github.com/HoudiniGraphql/houdini/issues/543
let { TestMutationUpdateUsersList } = data;
$: ({ TestMutationUpdateUsersList } = data);
async function update() {
await GQL_UpdateUser.mutate({
Expand All @@ -32,7 +29,7 @@
<button id="revert" on:click={revert}>Reset User</button>

<ul>
{#each $usersList.data?.usersList ?? [] as user}
{#each $TestMutationUpdateUsersList.data?.usersList ?? [] as user}
<li>
{user.id} - {user.name}
</li>
Expand Down
18 changes: 18 additions & 0 deletions integration/src/routes/stores/mutation-update/+page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { graphql, load_TestMutationUpdateUsersList } from '$houdini';
import type { LoadEvent } from '@sveltejs/kit';

export async function load(event: LoadEvent) {
return {
...(await load_TestMutationUpdateUsersList({ event }))
};
}

graphql`
query TestMutationUpdateUsersList {
usersList(limit: 5, snapshot: "update-user-mutation") {
id
name
...UserInfo
}
}
`;
5 changes: 5 additions & 0 deletions src/runtime/stores/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ If this is leftovers from old versions of houdini, you can safely remove this \`
// we have a new subscriber
this.subscriberCount = (this.subscriberCount ?? 0) + 1

// make sure that the store is always listening to the cache (on the browser)
if (isBrowser && !this.subscriptionSpec) {
this.refreshSubscription(this.lastVariables ?? ({} as _Input))
}

// Handle unsubscribe
return () => {
// we lost a subscriber
Expand Down

2 comments on commit cd00b5f

@vercel
Copy link

@vercel vercel bot commented on cd00b5f Sep 17, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

docs-next – ./site

docs-next-kohl.vercel.app
docs-next-git-main-houdinigraphql.vercel.app
docs-next-houdinigraphql.vercel.app

@vercel
Copy link

@vercel vercel bot commented on cd00b5f Sep 17, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.