Skip to content

Conversation

@1egoman
Copy link
Contributor

@1egoman 1egoman commented Nov 12, 2025

Per a note in #1230 (comment), I've made a follow up change which does some work to make session.start have a fully stable reference.

With these changes, a snippet like the below will now work as expected:

const session = useSession(/* ... */);

useEffect(() => {
  session.start();
  return () => {
    session.end();
  };
}, [session.start, session.end]);

As background context - the reason that session.start's reference changed so often was because it had a dependency on waitUntilConnected / agent.waitUntilAvailable, and each of these themselves had dependencies on session.connectionState and agent.state, which changed often. There wasn't really much of a con to making a localized copy of this state as a ref so after I did that in both cases the references became stable and those stable references cascaded up to make session.start stable!

@changeset-bot
Copy link

changeset-bot bot commented Nov 12, 2025

🦋 Changeset detected

Latest commit: 1aab460

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@livekit/components-react Patch
@livekit/component-example-next Patch
@livekit/components-js-docs Patch
@livekit/component-docs-storybook Patch
@livekit/components-docs-gen Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Nov 12, 2025

size-limit report 📦

Path Size
LiveKitRoom only 6 KB (0%)
LiveKitRoom with VideoConference 32.26 KB (+0.12% 🔺)
All exports 43.01 KB (+0.11% 🔺)

@1egoman 1egoman requested a review from lukasIO November 12, 2025 09:24
Copy link
Contributor

@lukasIO lukasIO left a comment

Choose a reason for hiding this comment

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

lgtm

It had a dependency on `room.connectionState` so that it could bail if the state was
the expected state when being initially called, but this had the side
effect of causing it to change reference often. So, cache this in a ref
instead.
It had a dependency on `state` so that it could bail if the state was
the expected state when being initially called, but this had the side
effect of causing it to change reference often. So, cache this in a ref
instead.
@1egoman 1egoman force-pushed the make-use-session-start-more-stable branch from 2b07d32 to 4923869 Compare November 13, 2025 06:59
@1egoman 1egoman merged commit 55e3d3a into main Nov 13, 2025
6 checks passed
@1egoman 1egoman deleted the make-use-session-start-more-stable branch November 13, 2025 07:03
@github-actions github-actions bot mentioned this pull request Nov 13, 2025
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.

3 participants