Skip to content

Conversation

@1egoman
Copy link
Contributor

@1egoman 1egoman commented Oct 23, 2025

This is being done to make them fit a bit better into the existing trackRef prop on a few components, which right now accepts TrackReference | undefined.

I think given the history of how things evolved with TrackReferences it makes sense to do this, but I think it's a rather unfortunate change to make since null and undefined semantically tend to mean different things in javascript (more info, other interesting read) and this case to me is semantically much more of a "null" (explicit absence of a value) than an "undefined" (value was never set).

Maybe it's something to litigate further as part of the next major version, however.

…ce values

This is being done to make them fit a bit better into the existing
`trackRef` prop on a few components, which right now accepts `TrackReference | undefined`.

I think given the history of how things evolved with `TrackReference`s it makes
sense to do this, but I think it's a rather unfortunate change to make since null
and undefined semantically tend to mean different things ([more
info](https://kettanaito.com/blog/the-difference-between-null-and-undefined), [other interesting read](https://medium.com/@stephenthecurt/a-brief-history-of-null-and-undefined-in-javascript-c283caab662e))
and this case to me is semantically much more of a "null" (explicit absence
of a value) than an "undefined" (value was never set).
@changeset-bot
Copy link

changeset-bot bot commented Oct 23, 2025

🦋 Changeset detected

Latest commit: 33c710c

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

@1egoman 1egoman changed the title feat: change useAgent to return undefined for nullable TrackReference values Change useAgent to return undefined for nullable TrackReference values Oct 23, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Oct 23, 2025

size-limit report 📦

Path Size
LiveKitRoom only 6 KB (0%)
LiveKitRoom with VideoConference 32.23 KB (0%)
All exports 42.57 KB (+0.21% 🔺)

Comment on lines 468 to 471
// Clear inner values if no longer connected
cameraTrack: null,
microphoneTrack: null,
cameraTrack: undefined,
microphoneTrack: undefined,
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just wanted to call out that I kept these key: undefined type entries here so that destructuring would continue to work coming out of useAgent - ie, const { cameraTrack, microphoneTrack } = useAgent(session). Otherwise this pattern would break down because cameraTrack + microphoneTrack wouldn't always be in the return value.

@1egoman 1egoman requested a review from lukasIO October 23, 2025 14:43
@1egoman 1egoman marked this pull request as ready for review October 23, 2025 14:43
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.

I agree we can/should make more deliberate choices about undefined vs null for future versions. Thanks for addressing and treating it as a compatibility fix

@1egoman 1egoman merged commit ca070d8 into main Oct 23, 2025
6 checks passed
@1egoman 1egoman deleted the switch-session-track-refs-to-undefined branch October 23, 2025 15:09
@github-actions github-actions bot mentioned this pull request Oct 23, 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