Skip to content

Commit 152e41d

Browse files
committed
fix: proper fragment subscription cleanup
1 parent c3026c5 commit 152e41d

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

.changeset/twenty-trains-wish.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"solid-relay": patch
3+
---
4+
5+
fix: proper fragment subscription cleanup

src/primitives/createFragment.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ import {
1414
KeyTypeData,
1515
} from "relay-runtime/lib/store/FragmentTypes";
1616
import type { Accessor, Setter, Signal } from "solid-js";
17-
import { batch, createResource, createSignal, untrack } from "solid-js";
17+
import { batch, createEffect, createResource, createSignal, onCleanup, untrack } from "solid-js";
1818
import { reconcile, type SetStoreFunction, unwrap } from "solid-js/store";
19-
import { isServer } from "solid-js/web";
2019
import { useRelayEnvironment } from "../RelayEnvironment";
2120
import { createDataStore, type DataStore } from "../utils/dataStore";
2221
import { cleanSnapshot } from "../utils/snapshot";
@@ -154,6 +153,14 @@ export function createFragmentInternal<
154153
},
155154
} satisfies Observer<FragmentState<unknown>>;
156155
const [subscription, setSubscription] = createSignal<Subscription>();
156+
createEffect(() => {
157+
const sub = subscription();
158+
if (sub) {
159+
onCleanup(() => {
160+
sub.unsubscribe();
161+
});
162+
}
163+
});
157164

158165
const setResultQueue: unknown[][] = [];
159166
let setResult: SetStoreFunction<FragmentResult<unknown>> = (...args: unknown[]) => {
@@ -164,7 +171,6 @@ export function createFragmentInternal<
164171
const [resource] = createResource(
165172
() => {
166173
return batch(() => {
167-
untrack(subscription)?.unsubscribe();
168174
setSubscription(undefined);
169175
setResult("pending", false);
170176

@@ -203,11 +209,6 @@ export function createFragmentInternal<
203209
},
204210
}),
205211
);
206-
}).finally(() => {
207-
if (isServer) {
208-
subscription()?.unsubscribe();
209-
setSubscription(undefined);
210-
}
211212
});
212213
},
213214
{

0 commit comments

Comments
 (0)