What is `join_ref` used for in Phoenix Channels?

How exactly is join_ref used is Phoenix Channels?

I tried poking around in phoenix.js and the Channels documentation, but it’s unclear to me exactly what it does. Thanks!

1 Like

Thanks Chris, I understand what it’s intended for, but how exactly is it used / why is it necessary? Is it used to manage duplicate channel joins? I see it didn’t exist in the v1 JSON serializer, but added in v2. I assume it was added to address a particular use case / problem that wasn’t obvious in v1? What would happen if join_ref didn’t exist? If I’m using the v1 JSON serializer, are there edge cases that aren’t handled?

Upon further investigation, my current understanding (based on this Github PR) is that join_ref was added to handle the race condition around leaving and rejoining the same channel.

Which implies V1 of the JSON serializer does not handle this race condition.

1 Like