Skip to content

fix(react): ignore stale token responses - #1454

Open
fatihcvs wants to merge 1 commit into
livekit:mainfrom
fatihcvs:fix/token-stale-response
Open

fatihcvs wants to merge 1 commit into
livekit:mainfrom
fatihcvs:fix/token-stale-response

Conversation

@fatihcvs

Copy link
Copy Markdown

Changing useToken's endpoint, room or user starts a new request, but a slower response from the previous request can overwrite the newer token. The same race happens when the old response's JSON body finishes late.

Ignore state updates from an effect after its cleanup has run. This preserves the existing request and return API while ensuring obsolete requests cannot replace the current request's result. Includes a React patch changeset.

Validation:

  • Four regression cases fail before the fix with old-token instead of new-token: endpoint, room and user changes, plus delayed JSON parsing.
  • The tests use the real hook and Response objects in JSDOM, with controlled fetch/body promises. No network request or live token service is involved.
  • 122 React/core/styles tests pass. React build (three package tasks), React lint (existing warnings, no errors), repository format and React API checks pass.

Developed and verified with OpenAI Codex assistance.

@changeset-bot

changeset-bot Bot commented Sep 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7704ef5

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

This PR includes changesets to release 6 packages
Name Type
@livekit/components-react Patch
@livekit/agents-ui 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

@vercel

vercel Bot commented Sep 20, 2026

Copy link
Copy Markdown

@fatihcvs is attempting to deploy a commit to the LiveKit Team on Vercel.

A member of the Team first needs to authorize it.

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.

1 participant