Skip to content

Migrate to partyserver (cloudflare/partykit)#59

Open
jessa0 wants to merge 3 commits intospencerc99:mainfrom
jessa0:partyserver
Open

Migrate to partyserver (cloudflare/partykit)#59
jessa0 wants to merge 3 commits intospencerc99:mainfrom
jessa0:partyserver

Conversation

@jessa0
Copy link

@jessa0 jessa0 commented Jan 5, 2026

PartyKit was moved to cloudflare/partykit on github (from partykit/partykit), and the new packages had a 0.1.0 release two weeks ago. This PR migrates to the new partyserver package replacing partykit, and y-partyserver replacing y-partykit.

This probably needs a major version bump, as I didn't see any guarantee of compatibility with the old PartyKit, though it was pretty close to compatible, at least. Old clients will definitely not be compatible, as I decided to use YServer's new CustomMessage API instead of overriding onMessage, since the old way of sending playhtml-layer messages relied on PartyKit just incidentally not using text websocket messages. Please let me know if I should create a changeset.

Motivation: I am experimenting with playhtml, but wanted to deploy in the "cloud-prem" configuration (PartyKit on own cloudflare account). I got stuck with PartyKit not being able to deploy to a free Cloudflare account, and noticed advice from the PartyKit authors (but can't find the link to that conversation, sorry..) to migrate to cloudflare/partykit instead. So I went down that rabbit hole..

jessa0 added 3 commits January 4, 2026 20:57
PartyKit was moved to `cloudflare/partykit` on github (from
`partykit/partykit`), and the new packages had a 1.0.0 release two weeks
ago. This commit migrates to the new `partyserver` package replacing
`partykit`, and `y-partyserver` replacing `y-partykit`.

This probably needs a major version bump, as I didn't see any guarantee
of compatibility with the old PartyKit, though it was pretty close to
compatible, at least. Old clients will definitely not be compatible, as
I decided to use YServer's new CustomMessage API instead of overriding
onMessage, since the old way of sending playhtml-layer messages relied
on PartyKit just incidentally not using text websocket messages.
We check in only the generated types without the runtime. This means
there are still some type errors related to the Cloudflare Workers API,
because we are still using `@cloudflare/worker-types`, which has been
deprecated.
Fix onLoad discarding the newly loaded document
@jessa0
Copy link
Author

jessa0 commented Jan 6, 2026

Fixed a bug with loading from DB. I haven't tested this PR with supabase yet (I probably will this week).

@spencerc99
Copy link
Owner

thanks for making this! my main worry with that we don't run into any data loss. im gonna check in with the partytkit authors to get a second pair of eyes

"changeset": "changeset",
"version-packages": "changeset version",
"release": "bun run build-packages && changeset publish",
"generate-types": "bunx wrangler types --include-runtime=false",
Copy link
Owner

Choose a reason for hiding this comment

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

nice good catch

Copy link
Author

Choose a reason for hiding this comment

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

It'd probably be even better to do --include-runtime=true as well, since @cloudflare/worker-types is mostly deprecated, and there seemed to be a couple type errors I couldn't seem to fix with @cloudflare/worker-types as well.. I just wanted to run that by you first. That flag generates more accurate types for the entire runtime, based on the compatibility_date you set in the wrangler config.

If you wanna do that, I'd also ask if you rather have the worker-configuration.d.ts checked in to the repo or generated at compile-time.

@jessa0
Copy link
Author

jessa0 commented Jan 12, 2026

thanks for making this! my main worry with that we don't run into any data loss. im gonna check in with the partytkit authors to get a second pair of eyes

That makes sense. I can also give it a second pass with data migration in mind if you want, as I didn't really do that for this draft.

@spencerc99
Copy link
Owner

hi @jessa0 sorry for the delay here! couldn't get a hold of the partykit folks but i think it should be fine since im persisting the data separately anyways.

going to actually take a look this week. thanks for putting this up again!

@spencerc99
Copy link
Owner

@jessa0 im actually curious - could you try deploying this as you originally desired and swapping in your provider URL for use with the playhtml library and seeing if everything works?

If there is danger of compatibility for me switching the main partykit server while the partyserver package is still in development to parity, we can hold off on merging this in, but that doesn't stop you from using this version to do your own on-prem since you'd just be swapping in the provider URL

@jessa0
Copy link
Author

jessa0 commented Feb 28, 2026

@jessa0 im actually curious - could you try deploying this as you originally desired and swapping in your provider URL for use with the playhtml library and seeing if everything works?

I finally got around to testing this, and the new partykit stuff does seem to be backward compatible: I tried deploying the new partyserver, and could switch between the new and old client codebases with the latest data loading on each. I played around with the objects on the main page and on the fridge. The cursor code is currently loaded separately from your domain, so I didn't properly test that.

Edit: What I said about compatibility in the PR description -- "Old clients will definitely not be compatible, as I decided to use YServer's new CustomMessage API instead of overriding onMessage" -- still holds though, in that any custom messages (e.g. "room-reset", "add-shared-reference", "register-shared-element", events sent through dispachPlayEvent, etc..) won't be communicated between new and old clients. However, new client <-> new client obviously works, and old <--> old might still work (but I haven't tested that).

Edit 2: Old client <-> old client custom messages do not work. I just confirmed by trying experiment two, which did not show confetti when clicking on the old client, but did work with the new client. I guess this makes sense, given that I removed the code in the partyserver that relays the old client messages (lol), but its been a while since I wrote this PR now. I actually have an idea to fix this to maintain compatibility between new and old clients, if you want? Let me know.

@jessa0
Copy link
Author

jessa0 commented Feb 28, 2026

If there is danger of compatibility for me switching the main partykit server while the partyserver package is still in development to parity, we can hold off on merging this in, but that doesn't stop you from using this version to do your own on-prem since you'd just be swapping in the provider URL

Oh, is there missing functionality in the new partyserver package? I didn't run into anything that you used that was removed.

@spencerc99
Copy link
Owner

It doesn't have to be backwards compatible with old clients if i understand what you mean by that (browser tabs that haven't refreshed the page)? So they would just be able to refresh and be on a new client and connect properly?

If that's the case im happy to take a look at merging this in next week (sorry for all the merge conflicts..)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants