New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
SSR presence #153
SSR presence #153
Conversation
This adds an onRequest handler to partykit to get the current presence on a regular HTTP request. We use that response to populate initial state during SSR, and then takeover with websockets after render. (Additionally, this removes some config and files that aren't used anymore from the presence package)
@@ -15,6 +15,21 @@ export function usePresencePreferences() { | |||
|
|||
type User = Pick<ReturnType<typeof useUser>, 'id' | 'name' | 'avatarUrl'> | |||
|
|||
export async function getPresentUsers(): Promise<User[]> { | |||
const presence = (await fetch( | |||
// 'http://127.0.0.1:1999/party/epic-web-presence', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
node 18 has issues fetching from localhost, so we switch to 127.0.0.1 instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Just a few questions.
packages/presence/src/server.ts
Outdated
if (req.method === 'POST') { | ||
return Response.json(this.getPresenceMessage().payload) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do a little bit of routing here so it can have a more descriptive path?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes we can! But I discovered a bug, that we need to land this fix for partykit/partykit#503 Might be a day before that happens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, I have a workaround that doesn't need us to land that fix. gimme a min.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aight, whaddaya think?
馃帀 This PR is included in version 2.45.1 馃帀 The release is available on: Your semantic-release bot 馃摝馃殌 |
This adds an onRequest handler to partykit to get the current presence on a regular HTTP request. We use that response to populate initial state during SSR, and then takeover with websockets after render.
(Additionally, this removes some config and files that aren't used anymore from the presence package)
@kentcdodds I tested that this "works", but I seem to have found myself in some weird cyclic typescript definition hell 馃槙