Skip to content

fix: invalidate stale video renderer attachments and respect ownership - #1222

Merged
xianshijing-lk merged 11 commits into
livekit:mainfrom
totem-technologies:fix/web-video-renderer-lifecycle
Nov 18, 2026
Merged

xianshijing-lk merged 11 commits into
livekit:mainfrom
totem-technologies:fix/web-video-renderer-lifecycle

Conversation

@bdlukaa

@bdlukaa bdlukaa commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem

VideoTrackRenderer can finish renderer initialization or listener replacement after its track has changed or its widget has been disposed. A stale async attachment can then install a listener for the wrong track or update a renderer that no longer belongs to that widget State.

Reproduction

Delay renderer initialization or disposal of the current track listener. While it is pending, replace the track (including A → B → C) or unmount the widget.
The previous attachment has no validity check after its await.

Fix

  • Invalidate in-flight attachments when the track, renderer, effective render mode, or widget lifecycle changes.
  • Keep initialization work out of repeated builds and attach only for the current generation.
  • Guard stream and resize callbacks against stale generations.
  • Detach cached renderers without disposing caller-owned instances; dispose widget-owned renderers according to autoDisposeRenderer.

Related to flutter-webrtc/flutter-webrtc#2227

@bdlukaa
bdlukaa marked this pull request as ready for review September 24, 2026 20:57
devin-ai-integration[bot]

This comment was marked as resolved.

This comment was marked as resolved.

@bdlukaa
bdlukaa marked this pull request as draft September 24, 2026 22:31
devin-ai-integration[bot]

This comment was marked as resolved.

@bdlukaa

bdlukaa commented Sep 27, 2026

Copy link
Copy Markdown
Contributor Author

This is not a breaking change as the tests say. The API is the same.

@bdlukaa
bdlukaa marked this pull request as ready for review October 5, 2026 13:49
devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@cloudwebrtc

Copy link
Copy Markdown
Contributor

This looks like a good fix and refactor. cc @hiroshihorie , @xianshijing-lk

devin-ai-integration[bot]

This comment was marked as resolved.

@bdlukaa

bdlukaa commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Hello, @hiroshihorie! Can I get a feedback on this? Thanks.

@xianshijing-lk

Copy link
Copy Markdown
Contributor

Sorry for the delay, I am reviewing it now.

@xianshijing-lk xianshijing-lk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed the lifecycle changes and validated compatibility and cached-renderer ownership with base/head probes. All 10 lifecycle tests pass and current-head analysis is clean. Two correctness comments and one non-blocking documentation request are inline; the default-web rendering finding is source-validated, with the browser execution limitation noted.

@xianshijing-lk xianshijing-lk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great work!! I like the clean up and fix.

Just some comments to minor problems, could you please address them and fix the CI, then we can land the PR.

@xianshijing-lk
xianshijing-lk merged commit 8cd6c48 into livekit:main Nov 18, 2026
16 checks passed
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.

4 participants