Avoid nested read locking when rendering browser sign-in (#47861)

## Why

`render_ref` already holds a read lock on `sign_in_state`. Acquiring another read lock in `render_continue_in_browser` can deadlock when a writer is waiting.

## What changed

Pass the borrowed `ContinueInBrowserState` from `render_ref` into the browser sign-in renderer instead of reading the lock again.

## Testing

Update the existing narrow-width browser sign-in test to exercise `render_ref`, retaining checks for the full OSC 8 authentication link, device-code guidance, and cancellation footer.

GitOrigin-RevId: ba83e212d510627be9dfd068c8d7318da32a1749
This commit is contained in:
jif
2026-09-24 15:21:29 +00:00
committed by copyberry
parent 58838dfa5b
commit 3e9d1d2937
+11 -9
View File
@@ -553,7 +553,12 @@ impl AuthModeWidget {
.render(area, buf);
}
fn render_continue_in_browser(&self, area: Rect, buf: &mut Buffer) {
fn render_continue_in_browser(
&self,
area: Rect,
buf: &mut Buffer,
state: &ContinueInBrowserState,
) {
let mut spans = vec![" ".into()];
if self.animations_enabled && !self.animations_suppressed.get() {
// Schedule a follow-up frame to keep the shimmer animation going.
@@ -568,10 +573,7 @@ impl AuthModeWidget {
}
let mut lines = vec![spans.into(), "".into()];
let sign_in_state = self.sign_in_state.read().unwrap();
let auth_url = if let SignInState::ChatGptContinueInBrowser(state) = &*sign_in_state
&& !state.auth_url.is_empty()
{
let auth_url = if !state.auth_url.is_empty() {
lines.push(" If the link doesn't open automatically, open the following link to authenticate:".into());
lines.push("".into());
lines.push(Line::from(vec![
@@ -1053,8 +1055,8 @@ impl WidgetRef for AuthModeWidget {
SignInState::PickMode => {
self.render_pick_mode(area, buf);
}
SignInState::ChatGptContinueInBrowser(_) => {
self.render_continue_in_browser(area, buf);
SignInState::ChatGptContinueInBrowser(state) => {
self.render_continue_in_browser(area, buf, state);
}
SignInState::ChatGptDeviceCode(state) => {
headless_chatgpt_login::render_device_code_login(self, area, buf, state);
@@ -1366,7 +1368,7 @@ mod tests {
let height = 30;
let area = Rect::new(0, 0, width, height);
let mut buf = Buffer::empty(area);
widget.render_continue_in_browser(area, &mut buf);
widget.render_ref(area, &mut buf);
let found = collect_osc8_chars(&buf, area, PRODUCTION_LENGTH_AUTH_URL);
assert_eq!(
@@ -1381,7 +1383,7 @@ mod tests {
terminal.set_viewport_area(area);
terminal
.draw(|frame| widget.render_continue_in_browser(area, frame.buffer_mut()))
.draw(|frame| widget.render_ref(area, frame.buffer_mut()))
.expect("draw");
let contents = terminal.backend().to_string();