Files
Danny White df77fc9011 fix(cli): resolve infinite loader on device code screen (#46137)
## Summary

Follow-up fix for
[#46120](https://github.com/supabase/supabase/pull/46120).

PR #46120 correctly guarded against duplicate `POST /platform/cli/login`
calls using a `useRef`, but left `navigate` in the `useEffect` deps
array. Because the parent passes an inline lambda, `navigate` gets a new
reference on every render. This causes React to:

1. Run the effect cleanup mid-flight (setting `isActive = false`)
2. Re-run the effect, which hits the session-id ref guard and returns
early

When step 1 happens while the POST is in-flight, the response arrives
with `isActive === false`, silently drops the `navigate(...)` call, and
leaves status stuck at `{ _tag: 'loading' }` — the infinite spinner
reported in Slack.

## Fix

Store `navigate` in a ref (updated each render) and call
`navigateRef.current(...)` inside `createSession`. Remove `navigate`
from the deps array so parent re-renders never trigger a cleanup while
the POST is in-flight.

```ts
const navigateRef = useRef(navigate)
navigateRef.current = navigate   // always up to date, never a dep
```

All 7 existing CLI login unit tests pass, including the "POSTs exactly
once even when parent re-renders" regression test.

## Test plan

- [ ] Run `pnpm test:studio tests/pages/cli-login.test.tsx` — all 7
tests pass
- [ ] Browser: `supabase login` flow completes and shows the
verification code screen without hanging on the loader
- [ ] DevTools Network: exactly one `POST /platform/cli/login` fires per
login attempt

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* Improved CLI login navigation reliability when parent components
update during session creation.

* **Style**
  * Adjusted loading indicator styling on the CLI login screen.

<!-- review_stack_entry_start -->

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/46137?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)

<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Gildas Garcia <1122076+djhi@users.noreply.github.com>
2026-05-20 12:26:02 +02:00
..