Commit 3c1d897
fix(nav): Add timeout recovery to prevent navigation hang after login
When router.push() is called during login redirect, it can succeed at the
JavaScript level while the underlying Next.js App Router fails to update
its internal state. This causes usePathname() to remain stale, leaving
the navigation machine stuck in a redirecting state with no escape path.
Root cause analysis:
- router.push('/') returns successfully (no error thrown)
- RSC request completes with HTTP 200
- But usePathname() never updates from '/login'
- The always guards can't fire because pathname hasn't changed
- CLEAR_SIDE_EFFECT only cleared context but had no target transition
This was observed specifically on cold sessions where:
1. Initial page load had expired tokens
2. Token refresh was attempted and failed (401)
3. User logged in successfully
4. Navigation to post-login destination hung
The App Router's internal navigation state appears to get corrupted when
there's been a failed auth cycle before the login, possibly due to:
- Concurrent RSC requests from the failed refresh interfering
- React Suspense boundary state not propagating correctly
- Cookie timing issues between refresh failure and login success
The fix adds a recovery transition: when CLEAR_SIDE_EFFECT fires with
reason='timeout', the machine now transitions to 'evaluating' instead of
staying stuck. This allows it to re-evaluate conditions and retry the
navigation, or at minimum reach a stable state the user can interact with.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>1 parent 2dbe976 commit 3c1d897
File tree
1 file changed
+69
-27
lines changed- app/src/atoms
1 file changed
+69
-27
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
262 | 262 | | |
263 | 263 | | |
264 | 264 | | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
274 | 287 | | |
275 | 288 | | |
276 | 289 | | |
| |||
309 | 322 | | |
310 | 323 | | |
311 | 324 | | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
321 | 347 | | |
322 | 348 | | |
323 | 349 | | |
| |||
475 | 501 | | |
476 | 502 | | |
477 | 503 | | |
478 | | - | |
479 | | - | |
480 | | - | |
481 | | - | |
482 | | - | |
483 | | - | |
484 | | - | |
485 | | - | |
486 | | - | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
487 | 529 | | |
488 | 530 | | |
489 | 531 | | |
| |||
0 commit comments