jaacsen
jaacsen
TtRPC
Created by jaacsen on 7/9/2024 in #❓-help
multiple subscriptions in client side causing latency and failing to reload/redirect
@BeBoRE @Alex / KATT 🐱
14 replies
TtRPC
Created by jaacsen on 7/9/2024 in #❓-help
multiple subscriptions in client side causing latency and failing to reload/redirect
when i replace wsLink in my client provider with httpSubscriptionLink, the subscriptions effectively do show in console after i subscribe
14 replies
TtRPC
Created by jaacsen on 7/9/2024 in #❓-help
multiple subscriptions in client side causing latency and failing to reload/redirect
i work with nextjs app router, setting websockets exactly like the example on github and it doesnt work for me.
14 replies
TtRPC
Created by jaacsen on 7/9/2024 in #❓-help
multiple subscriptions in client side causing latency and failing to reload/redirect
i've been tryin to fix the subscriptions issue for a week now, i dont know why its not working for me
14 replies
TtRPC
Created by jaacsen on 7/9/2024 in #❓-help
multiple subscriptions in client side causing latency and failing to reload/redirect
yes
14 replies
TtRPC
Created by jaacsen on 7/9/2024 in #❓-help
multiple subscriptions in client side causing latency and failing to reload/redirect
I am using SSE, when I try to call more than subscriptions on the same page, the page stops working properly, can't redirect to pages, nor gets refreshed
14 replies
TtRPC
Created by jaacsen on 7/2/2024 in #❓-help
Subscription error: TRPCClientError: Subscriptions should use wsLink
in the client provider
25 replies
TtRPC
Created by jaacsen on 7/2/2024 in #❓-help
Subscription error: TRPCClientError: Subscriptions should use wsLink
I have a question, @Alex / KATT 🐱 the subscription works when only I replace wsLink(...) with unstable_httpSubscriptionLink why is that?
25 replies
TtRPC
Created by jaacsen on 7/2/2024 in #❓-help
Subscription error: TRPCClientError: Subscriptions should use wsLink
No description
25 replies
TtRPC
Created by jaacsen on 7/2/2024 in #❓-help
Subscription error: TRPCClientError: Subscriptions should use wsLink
@Alex / KATT 🐱 what to do here?
25 replies
TtRPC
Created by jaacsen on 7/2/2024 in #❓-help
Subscription error: TRPCClientError: Subscriptions should use wsLink
Module '"@trpc/client"' has no exported member 'unstable_httpSubscriptionLink'.ts(2305)
25 replies
TtRPC
Created by jaacsen on 7/2/2024 in #❓-help
Subscription error: TRPCClientError: Subscriptions should use wsLink
been stuck on this for quite sometime
25 replies
TtRPC
Created by jaacsen on 7/2/2024 in #❓-help
Subscription error: TRPCClientError: Subscriptions should use wsLink
@Alex / KATT 🐱 any ideas pleasse?
25 replies
TtRPC
Created by jaacsen on 7/2/2024 in #❓-help
Subscription error: TRPCClientError: Subscriptions should use wsLink
sorry i dont understand ur qst
25 replies
TtRPC
Created by jaacsen on 7/2/2024 in #❓-help
Subscription error: TRPCClientError: Subscriptions should use wsLink
No description
25 replies
TtRPC
Created by jaacsen on 7/2/2024 in #❓-help
Subscription error: TRPCClientError: Subscriptions should use wsLink
onAdd: publicProcedure.subscription(() => {
// return an `observable` with a callback which is triggered immediately
return observable<Review>(emit => {
const onAdd = (data: Review) => {
// emit data to client
emit.next(data)
}
// trigger `onAdd()` when `add` is triggered in our event emitter
ee.on('add', onAdd)
// unsubscribe function when client disconnects or stops subscribing
return () => {
ee.off('add', onAdd)
}
})
}),
createReview: authedProcedure
.input(v => {
const schema = z.object({
...
})
const result = schema.safeParse(v)
if (!result.success) {
throw result.error
}
return result.data
})
.mutation(async ({ input, ctx }) => {
const session = await getServerAuthSession()

// Create the review record
const review = await db.review.create({
data: {
....
},

})
ee.emit('add', review)
return review
}),
onAdd: publicProcedure.subscription(() => {
// return an `observable` with a callback which is triggered immediately
return observable<Review>(emit => {
const onAdd = (data: Review) => {
// emit data to client
emit.next(data)
}
// trigger `onAdd()` when `add` is triggered in our event emitter
ee.on('add', onAdd)
// unsubscribe function when client disconnects or stops subscribing
return () => {
ee.off('add', onAdd)
}
})
}),
createReview: authedProcedure
.input(v => {
const schema = z.object({
...
})
const result = schema.safeParse(v)
if (!result.success) {
throw result.error
}
return result.data
})
.mutation(async ({ input, ctx }) => {
const session = await getServerAuthSession()

// Create the review record
const review = await db.review.create({
data: {
....
},

})
ee.emit('add', review)
return review
}),
25 replies
TtRPC
Created by jaacsen on 7/2/2024 in #❓-help
Subscription error: TRPCClientError: Subscriptions should use wsLink
import ws from 'ws'
import { applyWSSHandler } from '@trpc/server/adapters/ws'
import { appRouter } from './routers/_app'
import { createContext, createTRPCContext } from './context'

const wss = new ws.Server({
port: 3001
})

const handler = applyWSSHandler({ wss, router: appRouter, createContext: createTRPCContext })

wss.on('connection', () => {
console.log(`Got a connection ${wss.clients.size}`)
wss.once('close', () => {
console.log(`Closed connection ${wss.clients.size}`)
})
})

console.log(`wss server start at ws://localhost:3001`)

process.on('SIGTERM', () => {
console.log('Got SIGTERM')
handler.broadcastReconnectNotification()
wss.close()
})
import ws from 'ws'
import { applyWSSHandler } from '@trpc/server/adapters/ws'
import { appRouter } from './routers/_app'
import { createContext, createTRPCContext } from './context'

const wss = new ws.Server({
port: 3001
})

const handler = applyWSSHandler({ wss, router: appRouter, createContext: createTRPCContext })

wss.on('connection', () => {
console.log(`Got a connection ${wss.clients.size}`)
wss.once('close', () => {
console.log(`Closed connection ${wss.clients.size}`)
})
})

console.log(`wss server start at ws://localhost:3001`)

process.on('SIGTERM', () => {
console.log('Got SIGTERM')
handler.broadcastReconnectNotification()
wss.close()
})
25 replies
TtRPC
Created by jaacsen on 7/2/2024 in #❓-help
Subscription error: TRPCClientError: Subscriptions should use wsLink
here is a detailed vers:
"dev": "run-p dev:*",
"dev:next": "next dev",
"dev:wss": "cross-env PORT=3001 nodemon --watch src --ext .ts,.tsx,js,jsx --signal SIGTERM --exec \"ts-node --project tsconfig.server.json src/server/wsServer.ts\"",
"dev": "run-p dev:*",
"dev:next": "next dev",
"dev:wss": "cross-env PORT=3001 nodemon --watch src --ext .ts,.tsx,js,jsx --signal SIGTERM --exec \"ts-node --project tsconfig.server.json src/server/wsServer.ts\"",
export const trpc = createTRPCNext<AppRouter>({
/**
* @link https://trpc.io/docs/v11/ssr
*/
// ssr: true,
// ssrPrepass,
ssr: false,
config({ ctx }) {
/**
* If you want to use SSR, you need to use the server's full URL
* @link https://trpc.io/docs/v11/ssr
*/

return {
/**
* @link https://trpc.io/docs/v11/client/links
*/
links: [
// adds pretty logs to your console in development and logs errors in production
loggerLink({
enabled: opts =>
(process.env.NODE_ENV === 'development' && typeof window !== 'undefined') ||
(opts.direction === 'down' && opts.result instanceof Error)
}),
splitLink({
condition: op => {
return op.type === 'subscription'
},
true: wsLink({
client: createWSClient({
url: 'ws://localhost:3001'
})
}),
false: httpBatchLink({
transformer: superjson,
url: `http://localhost:3000/api/trpc`
})
})
],
/**
* @link https://tanstack.com/query/v5/docs/reference/QueryClient
*/
queryClientConfig: { defaultOptions: { queries: { staleTime: 60 } } }
}
},
/**
* @link https://trpc.io/docs/v11/data-transformers
*/
transformer: superjson
})
export const trpc = createTRPCNext<AppRouter>({
/**
* @link https://trpc.io/docs/v11/ssr
*/
// ssr: true,
// ssrPrepass,
ssr: false,
config({ ctx }) {
/**
* If you want to use SSR, you need to use the server's full URL
* @link https://trpc.io/docs/v11/ssr
*/

return {
/**
* @link https://trpc.io/docs/v11/client/links
*/
links: [
// adds pretty logs to your console in development and logs errors in production
loggerLink({
enabled: opts =>
(process.env.NODE_ENV === 'development' && typeof window !== 'undefined') ||
(opts.direction === 'down' && opts.result instanceof Error)
}),
splitLink({
condition: op => {
return op.type === 'subscription'
},
true: wsLink({
client: createWSClient({
url: 'ws://localhost:3001'
})
}),
false: httpBatchLink({
transformer: superjson,
url: `http://localhost:3000/api/trpc`
})
})
],
/**
* @link https://tanstack.com/query/v5/docs/reference/QueryClient
*/
queryClientConfig: { defaultOptions: { queries: { staleTime: 60 } } }
}
},
/**
* @link https://trpc.io/docs/v11/data-transformers
*/
transformer: superjson
})
25 replies
TtRPC
Created by jaacsen on 7/2/2024 in #❓-help
Subscription error: TRPCClientError: Subscriptions should use wsLink
it doesn't actually I am not sure where I am wrong
25 replies
TtRPC
Created by jaacsen on 7/2/2024 in #❓-help
Subscription error: TRPCClientError: Subscriptions should use wsLink
anyone help please? im stuck and I dont know what shopuld I do here, heres a stackoverflow explaination of my issue https://stackoverflow.com/questions/78653455/error-subscriptions-should-use-wslink-using-trpc
25 replies