Repository navigation
Conversation
|
This pull request is being automatically deployed with Vercel (learn more). next-prisma-starter – ./examples/next-prisma-starter🔍 Inspect: https://vercel.com/trpc/next-prisma-starter/6ZYtyghmcRXNratVgdgzgrSbBhb4 www – ./www🔍 Inspect: https://vercel.com/trpc/www/J5ksH3Gdprp5pm27veuBCAwadY2h |
148d81f to
f06dbe2
Compare
1eb0468 to
0e02261
Compare
|
It seems that one of the build jobs is timing out and therefore failing - Could you take a look @KATT ? |
|
Just re-run the tests looks like it didn't timeout this time. Awaiting your feedback @KATT 👍 |
|
I still really struggle to see how this should be a client-side concern to keep track of? 🤔 |
|
I really appreciate you're doing this. Maybe you can share more details of your use-case @jlalmes, and why this isn't something the server can pick up on it's own? To me, it looks like something that the server should "know" after the createContext is called, which happens on first connect for WebSockets too. |
|
Hi @KATT, thanks for getting back to me. Use case - I am working on an internal web analytics tool:
Reason for this PR
Why I propose this API
Current workaround const subscribe = () => {
const unsubscribe = trpcWsClient.subscription('session', { sessionId: window.sessionStorage.getItem('session') }, {
onNext: (result) => {
if (result.type === 'data') {
window.sessionStorage.setItem('session', result.data.sessionId);
}
},
onError: (error) => {
console.error(error);
unsubscribe();
subscribe();
},
});
};
subscribe();Usage after this PR trpcWsClient.subscription('session', () => ({ sessionId: window.sessionStorage.getItem('session') }), {
onNext: (result) => {
if (result.type === 'data') {
window.sessionStorage.setItem('session', result.data.sessionId);
}
}
});Let me know if this is not clear. Thanks |
|
Hmmm.. is there a reason why you aren't using a session cookie? Cookies are usually the way to deal with this on the web |
|
Fair point I suppose, closing this PR & issue for now. |
Pull request was closed
|
I really appreciate the work you did on this @jlalmes, feel free to reopen a discussion about it if you feel it's something we should support! |
|
This pull request has been locked because it had no new activity for 30 days. If you think, this PR is still necessary, create a new one with the same branch. Thank you. |
This PR implements a backwards compatible way to optionally specify the subscription input payload as a function. The input value is resolved by this function each time the socket reconnects.
These changes do not affect the
useSubscriptionhook in@trpc/react, only the rawTRPCClientfrom@trpc/client.Closes #1574