Skip to content
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

Merged
merged 5 commits into from Oct 17, 2023
Merged

SSR presence #153

merged 5 commits into from Oct 17, 2023

Conversation

threepointone
Copy link
Contributor

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 馃槙

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',
Copy link
Contributor Author

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

Copy link
Member

@kentcdodds kentcdodds left a 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/workshop-app/app/routes/_app+/presence.ts Outdated Show resolved Hide resolved
Comment on lines 65 to 67
if (req.method === 'POST') {
return Response.json(this.getPresenceMessage().payload)
}
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aight, whaddaya think?

@kentcdodds kentcdodds marked this pull request as ready for review October 17, 2023 15:52
@kentcdodds kentcdodds merged commit 92d3d74 into epicweb-dev:main Oct 17, 2023
8 checks passed
@github-actions
Copy link

馃帀 This PR is included in version 2.45.1 馃帀

The release is available on:

Your semantic-release bot 馃摝馃殌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants