Skip to content

fix: replicate story IDs so peers joining mid-session can key results - #13

Merged
JheisonMB merged 2 commits into
mainfrom
develop
Aug 13, 2026
Merged

fix: replicate story IDs so peers joining mid-session can key results#13
JheisonMB merged 2 commits into
mainfrom
develop

Conversation

@JheisonMB

Copy link
Copy Markdown
Contributor

Story IDs key every saved result. They were host-local state that never crossed
the wire, which broke in three places at once:

  • A peer joining mid-session got undefined. state-sync rebuilds state
    field by field and omitted storyIds/storyId, so every path that indexes
    them threw — renderWaiting, startVoting, loadStories.
  • stories-load carried the stories without their IDs. The receiver
    replaced its list and kept the old IDs, leaving the two arrays misaligned:
    results attached to the wrong story.
  • storyId was only maintained in startVoting. After nextStory() it
    still pointed at the previous story — on the host too, not just on peers.

The fix removes the field rather than patching each site: storyId is no
longer stored, it is derived from currentIndex when the state is read, so it
cannot drift out of step. storyIds now travels with the stories it
identifies, and incoming lists are rebuilt to the same length as the stories —
an unusable ID is replaced in place, never dropped, since dropping would shift
every later ID onto the wrong story.

Nine tests, including the regression for the undefined state-sync. The reason
this shipped is worth recording: there was not a single test that mentioned
storyId.

@JheisonMB JheisonMB added the target:main PR targets main branch label Aug 13, 2026
@JheisonMB
JheisonMB merged commit b8bfc80 into main Aug 13, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

target:main PR targets main branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant