Repository navigation
feat: Enhance session management with logout - SFS-3105 - #3268
Conversation
…tracking - Added SESSION_READY_KEY to manage session readiness state after logout. - Updated checkAndReloadIfReturnedFromLogout to set session readiness on reload. - Modified createValidationStore to include hasValidatedStore for tracking validation completion. - Adjusted useSession and useSessionReady hooks to utilize hasValidated for improved session state management, addressing React 18 batching issues.
WalkthroughReplaces a locally defined reload key with shared storage keys, adds a persistent "hasValidated" store, updates session validation flow to short-circuit on a logout-return flag, and defers marking session-ready until validation has completed. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant SessionHook as Session Hook
participant ValidationStore as Validation Store
participant sessionStorage as sessionStorage
Client->>SessionHook: mount/useSession()
SessionHook->>ValidationStore: createValidationStore(validateSession)
SessionHook->>sessionStorage: read RELOAD_AFTER_LOGOUT_KEY?
alt reload-after-logout present
SessionHook->>sessionStorage: remove RELOAD_AFTER_LOGOUT_KEY
SessionHook->>sessionStorage: set SESSION_READY_KEY = "true"
SessionHook->>Client: schedule forceRefreshWithoutCache (delayed)
else normal flow
SessionHook->>ValidationStore: onValidate() -> validateSession()
ValidationStore-->>ValidationStore: set hasValidated = true (finally)
ValidationStore-->>SessionHook: isValidating / hasValidated updates
SessionHook->>SessionHook: useSessionReady(!isValidating && hasValidated)
SessionHook-->>Client: session ready state true/false
end
Estimated Code Review Effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly Related PRs
Suggested Reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/core/src/sdk/session/index.ts`:
- Line 19: The SDK imports a UI component constant RELOAD_AFTER_LOGOUT_KEY from
MyAccountDrawer, creating a UI→SDK coupling; create a neutral module (e.g., add
packages/core/src/sdk/session/storageKeys.ts) that exports
RELOAD_AFTER_LOGOUT_KEY (and any other keys like SESSION_READY_KEY), then update
packages/core/src/sdk/session/index.ts to import RELOAD_AFTER_LOGOUT_KEY from
that new storageKeys module instead of the component path so SDK business logic
no longer depends on UI implementation details.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: e4c1e50f-e839-4cd7-aaf2-60fef31b9007
📒 Files selected for processing (3)
packages/core/src/components/account/MyAccountDrawer/OrganizationDrawer/useReloadAfterLogoutReturn.tspackages/core/src/sdk/session/index.tspackages/core/src/sdk/useStore.ts
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/core/src/components/account/MyAccountDrawer/OrganizationDrawer/useReloadAfterLogoutReturn.ts (1)
45-56:⚠️ Potential issue | 🟡 MinorConsider timing of SESSION_READY_KEY pre-set before page reload. ⏱️
Setting
SESSION_READY_KEY = 'true'on line 50 happens ~1s before the hard navigation. During that window, when the return page initializes its session store,useSessionReadywill:
- Initialize
isSessionReadystate totrue(from the pre-set flag)- Run its validation effect, which guards with
if (isValidating || !hasValidated) returnComponents reading the store state during this brief window could render as "ready" before validation completes. However, this is mitigated by the hard reload occurring within ~1s, and the validation flow on the reloaded page will always run to correct the state regardless of the pre-seeded flag.
If you want to eliminate this timing window entirely, move the
setItemcall immediately beforewindow.location.replaceinsideforceRefreshWithoutCacheto shrink the observable gap. Otherwise, the current pattern is acceptable if you're confident validation completes within ~1s on typical page hydration.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/core/src/components/account/MyAccountDrawer/OrganizationDrawer/useReloadAfterLogoutReturn.ts` around lines 45 - 56, The SESSION_READY_KEY is being set in checkAndReloadIfReturnedFromLogout before the delayed hard navigation, creating a brief window where components may see the session as ready; move the session pre-set into forceRefreshWithoutCache immediately before performing the navigation (i.e., remove sessionStorage.setItem(SESSION_READY_KEY, 'true') from checkAndReloadIfReturnedFromLogout and instead set sessionStorage.setItem(SESSION_READY_KEY, 'true') inside forceRefreshWithoutCache just prior to calling window.location.replace) so the observable gap between setting SESSION_READY_KEY and the reload is eliminated; keep use of RELOAD_DELAY_MS and setTimeout(call to forceRefreshWithoutCache) intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In
`@packages/core/src/components/account/MyAccountDrawer/OrganizationDrawer/useReloadAfterLogoutReturn.ts`:
- Around line 45-56: The SESSION_READY_KEY is being set in
checkAndReloadIfReturnedFromLogout before the delayed hard navigation, creating
a brief window where components may see the session as ready; move the session
pre-set into forceRefreshWithoutCache immediately before performing the
navigation (i.e., remove sessionStorage.setItem(SESSION_READY_KEY, 'true') from
checkAndReloadIfReturnedFromLogout and instead set
sessionStorage.setItem(SESSION_READY_KEY, 'true') inside
forceRefreshWithoutCache just prior to calling window.location.replace) so the
observable gap between setting SESSION_READY_KEY and the reload is eliminated;
keep use of RELOAD_DELAY_MS and setTimeout(call to forceRefreshWithoutCache)
intact.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: ae649692-0ce3-4a01-88af-9904bc668909
📒 Files selected for processing (3)
packages/core/src/components/account/MyAccountDrawer/OrganizationDrawer/useReloadAfterLogoutReturn.tspackages/core/src/sdk/session/index.tspackages/core/src/sdk/session/storageKeys.ts
✅ Files skipped from review due to trivial changes (1)
- packages/core/src/sdk/session/storageKeys.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/core/src/sdk/session/index.ts
What's the purpose of this pull request?
How it works?
How to test it?
using b2b store url.
Summary by CodeRabbit
Bug Fixes
Refactor