javascript
javascript copied to clipboard
fix(clerk-js): Correct race condition when fetching tokens
Description
Fix race condition where multiple browser tabs could fetch session tokens simultaneously. The refreshTokenOnFocus handler now uses the same cross-tab lock as the session token poller, preventing duplicate API calls when switching between tabs or when focus events fire while another tab is already refreshing the token.
Checklist
- [ ]
pnpm testruns as expected. - [ ]
pnpm buildruns as expected. - [ ] (If applicable) JSDoc comments have been added or updated for any package exports
- [ ] (If applicable) Documentation has been updated
Type of change
- [ ] 🐛 Bug fix
- [ ] 🌟 New feature
- [ ] 🔨 Breaking change
- [ ] 📖 Refactoring / dependency upgrade / documentation
- [ ] other:
Summary by CodeRabbit
-
Bug Fixes
- Fixed race conditions that could cause duplicate session token fetches across tabs, reducing unnecessary network calls and sign-in glitches.
- Improved session polling reliability so retries are rescheduled even after errors.
-
New Features
- Added a cross-tab locking utility to coordinate token fetches and avoid redundant requests.
- Added ability to stop and restart session polling.
-
Tests
- Added comprehensive tests for polling, locking, and token refresh sequencing.
-
Chores
- Added a changeset for a patch release.
✏️ Tip: You can customize this high-level summary in your review settings.