Skip to content

Commit

Permalink
Revert changing addSubscription to an async function
Browse files Browse the repository at this point in the history
  • Loading branch information
HeavenVolkoff committed Oct 9, 2024
1 parent 9acb6ea commit cc2edf5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
9 changes: 6 additions & 3 deletions packages/client/src/v2/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ export class AlphaClient<P extends ProceduresDef> {
}
}

async addSubscription<
addSubscription<
K extends P['subscriptions']['key'] & string,
TData = inferProcedureResult<P, 'subscriptions', K>,
>(
keyAndInput: [K, ..._inferProcedureHandlerInput<P, 'subscriptions', K>],
opts: SubscriptionOptions<TData> & { context?: OperationContext }
): Promise<() => void> {
): () => void {
try {
const keyAndInput2 = this.mapQueryKey?.(keyAndInput) ?? keyAndInput

Expand All @@ -131,7 +131,10 @@ export class AlphaClient<P extends ProceduresDef> {
return result.abort
} catch (err) {
if (err instanceof RSPCError) {
if (this.onError) await this.onError(err)
if (this.onError)
this.onError(err)?.catch(error => {
console.error('Failure during onError handler for addSubscription', error)
})
return () => {}
}

Expand Down
5 changes: 1 addition & 4 deletions packages/react/src/v2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,10 @@ export function createReactQueryHooks<P extends ProceduresDef>(
if (!enabled) {
return
}
const subscription = client.addSubscription<K, TData>(keyAndInput, {
return client.addSubscription<K, TData>(keyAndInput, {
onData: opts.onData,
onError: opts.onError,
})
return () => {
subscription.then(unsubscribe => unsubscribe())
}
}, [queryKey, enabled])
}

Expand Down

0 comments on commit cc2edf5

Please sign in to comment.