Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

[Session] Rely on agent session change event for persisting resumed session (#3836)

* Rely on agent session change handler for resumption

* Add a fast path for noop resumes

authored by

dan and committed by
GitHub
cdf7a195 c9cf608f

+12 -32
+12 -32
src/state/session/index.tsx
··· 158 158 * out. 159 159 */ 160 160 setState(s => { 161 + const existingAccount = s.accounts.find( 162 + a => a.did === refreshedAccount.did, 163 + ) 164 + if ( 165 + !expired && 166 + existingAccount && 167 + refreshedAccount && 168 + JSON.stringify(existingAccount) === JSON.stringify(refreshedAccount) 169 + ) { 170 + // Fast path without a state update. 171 + return s 172 + } 161 173 return { 162 174 accounts: [ 163 175 refreshedAccount, ··· 379 391 380 392 // Intentionally not awaited to unblock the UI: 381 393 resumeSessionWithFreshAccount() 382 - .then(freshAccount => { 383 - if (JSON.stringify(account) !== JSON.stringify(freshAccount)) { 384 - logger.info( 385 - `session: reuse of previous session returned a fresh account, upserting`, 386 - ) 387 - setState(s => { 388 - return { 389 - accounts: [ 390 - freshAccount, 391 - ...s.accounts.filter(a => a.did !== freshAccount.did), 392 - ], 393 - currentAgentState: { 394 - did: freshAccount.did, 395 - agent: agent, 396 - }, 397 - needsPersist: true, 398 - } 399 - }) 400 - } 401 - }) 402 - .catch(e => { 403 - /* 404 - * Note: `agent.persistSession` is also called when this fails, and 405 - * we handle that failure via `createPersistSessionHandler` 406 - */ 407 - logger.info(`session: resumeSessionWithFreshAccount failed`, { 408 - message: e, 409 - }) 410 - 411 - __globalAgent = PUBLIC_BSKY_AGENT 412 - // TODO: This needs a setState. 413 - }) 414 394 } 415 395 416 396 async function resumeSessionWithFreshAccount(): Promise<SessionAccount> {