Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
This PR introduces visibility-aware session refresh behavior to prevent unnecessary token refreshes when the browser tab is in the background. This is a key requirement for session inactivity tracking, as refreshing tokens while the tab is hidden would incorrectly extend session lifetimes.
Key Changes:
- Defers token refresh when tab is hidden, marking it as needed instead
- Adds
ignoreVisibilityoption to preserve backward compatibility - Updates visibility change handler to recalculate timers when tab becomes visible
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/sdks/web-js-sdk/src/enhancers/withAutoRefresh/types.ts | Extends autoRefresh config to accept object with ignoreVisibility option |
| packages/sdks/web-js-sdk/src/enhancers/withAutoRefresh/index.ts | Implements deferred refresh logic with refreshNeeded flag and visibility checks |
| packages/sdks/web-js-sdk/test/autoRefresh.test.ts | Updates test to use new config format with ignoreVisibility: true |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // for a case that the token was refreshed from another tab, this mostly relevant | ||
| // when the project uses token rotation | ||
| sdk.refresh(getRefreshToken() || refreshJwt); | ||
| if (!ignoreVisibility && document.visibilityState === 'hidden') { |
There was a problem hiding this comment.
The document object may not be defined in non-browser environments despite the IS_BROWSER check at line 40. This timer callback could execute in contexts where document is undefined, causing a runtime error. Add a check for IS_BROWSER or ensure document is defined before accessing visibilityState.
| if (!ignoreVisibility && document.visibilityState === 'hidden') { | |
| if (!ignoreVisibility && IS_BROWSER && document.visibilityState === 'hidden') { |
packages/sdks/web-js-sdk/src/enhancers/withAutoRefresh/index.ts
Outdated
Show resolved
Hide resolved
|
| Command | Status | Duration | Result |
|---|---|---|---|
nx affected --target test:e2e |
❌ Failed | 7m 5s | View ↗ |
nx affected --target test |
✅ Succeeded | 3m 29s | View ↗ |
nx affected --target lint --fix=true |
✅ Succeeded | 5s | View ↗ |
nx affected --target build |
✅ Succeeded | 2m 56s | View ↗ |
nx affected --target licenseCheck |
✅ Succeeded | <1s | View ↗ |
☁️ Nx Cloud last updated this comment at 2025-12-04 13:51:24 UTC

Related Issues
Fixes https://github.com/descope/etc/issues/13001
Description
autoRefresh: { ignoreVisibility: true }to preserve old behaviorstill required tests