Skip to content

Focus the area cycle's page only once the host shows it and the core selects it - #565

Merged
yansfil merged 1 commit into
mainfrom
fix/area-cycle-focus-once-shown
Oct 5, 2026
Merged

yansfil merged 1 commit into
mainfrom
fix/area-cycle-focus-once-shown

Conversation

@yansfil

@yansfil yansfil commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Refs #433

Summary

#534 뒤로 desktop browser.spec.ts의 area cycle native가 자주 실패하던 것을 고칩니다(fix-forward).
page를 보이기 전에 focus하던 순서를, host가 page를 보이고 core snapshot이 그 page를 고른 뒤에 한 번 focus하는 순서로 바꿨습니다.
제품 코드는 바뀌지 않았습니다.

  • 실패는 두 번째 이후 focus(828행 tab click 뒤, 873행 설정 sheet를 Escape로 닫은 뒤)에서만 났습니다. 첫 번째 focus 앞에는 shell 조작이 없어서 통과합니다.
  • 원인(읽기): 첫 cycle이 Page B를 고른 뒤라 tab click 시점의 한글 브라우저 page는 숨겨져 있고, 그 page를 보이고 고르는 일은 click의 core 왕복이 끝나야 옵니다. sheet도 덮는 동안 page를 숨깁니다. #534의 focusPage는 그 사이에 한 번 focus합니다.
    • 숨겨진 page에 준 focus는 page가 보인 뒤 keyboard로 남지 않아, hold 확인이 5초 안에 참이 되지 않습니다(789행 실패).
    • 보인 뒤에도 core snapshot이 아직 그 page를 고르지 않았으면, page가 시작한 hold를 shell이 받지 않고 끝냅니다(web/src/keyboard.ts의 focusedSurface(...)?.id !== input.id 분기). 그래서 cycle이 그려지지 않습니다(831행 [data-cycle=area] 없음). host log에 browser.cycle_start_refused가 없는 것도 page가 hold를 시작했다는 것과 맞습니다.
    • Give a desktop page the keyboard once the window is key, not until it holds #534 전에는 focus를 되풀이하고 250ms 동안 유지되는지 보는 loop가 이 두 경합을 가렸습니다.
  • browser.spec.ts: shownAndSelected(host가 page를 보이고, tab bar에서 그 display가 선택됨)를 기다린 뒤 focusPage 한 번, 그다음 기존 확인(page가 keyboard를 쥐고 shell이 받아들임)을 기다립니다. 새 retry, timeout, sleep, allow는 없습니다.
  • fixture.ts focusPage 설명과 docs/BUILD.md에 "page가 보인 뒤에 focus한다"는 전제를 적었습니다.

Review

  • 판단해 주세요: tab bar의 aria-selected를 core snapshot이 고른 것으로 읽었습니다. tab click은 view_layout 하나를 보내고 화면은 snapshot으로만 그려져(낙관적 선택 없음, web/src/AreaTree.tsx focus), 선택이 보이면 core가 고른 것입니다.
  • 조심해서 볼 파일: desktop/e2e/fixture.ts focusPage - 숨겨진 page를 받으면 지금은 그대로 focus합니다. 그 자리에서 실패하게(view.getVisible()로 throw) 하는 것은 zoom과 close-policy 호출까지 바뀌어 이 급한 수정에서 뺐습니다.
  • 질문: 없음.

Evidence

  • 확인한 것: verify-web.sh desktop typecheck, desktop lint(test 크기 검사 포함) 통과. 실패 log 3개(pr-534 queue run 37339468790, Remove the merge queue path from verify #556 run 37344689288 attempt 1, 2)를 읽어 실패 행(828 다음 789, 831, 873 다음 789)과 host event를 확인했습니다.
  • 확인하지 못한 것: @needs-focus test는 운영자의 창과 keyboard를 가로채므로 로컬에서 돌리지 않았습니다. 이 PR의 CI desktop e2e lane 결과로만 확인합니다. 원인은 log와 코드로 읽은 것이고, 숨겨진 view에 준 focus가 보인 뒤 남지 않는다는 부분은 재현하지 않았습니다.

…selects it

After a tab click or a closed sheet, the page the native cycle starts from
is still hidden, or not yet selected in the core's snapshot, until that
action's round trip lands. Focused in that window, the page does not keep
the keyboard once shown, or the shell refuses the hold it starts because
the core does not yet select it. The spec now waits for the host to show
the page and the snapshot to select it, then focuses it once.
@yansfil
yansfil merged commit c76670c into main Oct 5, 2026
13 checks passed
@yansfil
yansfil deleted the fix/area-cycle-focus-once-shown branch October 5, 2026 18:23
yansfil added a commit that referenced this pull request Oct 6, 2026
)

Refs #511

## Summary

`area cycle native`가 #565 뒤에도 가끔 첫 시도에 실패하던 원인을 제품(desktop host)에서 고칩니다.
실패는 #565가 다룬 tab click이나 sheet 뒤 focus가 아니라 857행, 즉 window blur로 취소된
hold 뒤 window가 돌아왔을 때 page가 keyboard를 되찾는 단계였습니다.

- 원인: macOS의 Electron 44에서 window의 `focus` event는 window가 main이 될 때 나오고,
Electron은 그 직전에 `blur` 때 저장해 둔 focus를
되돌립니다(`BrowserWindow::OnWindowFocus`의 `RestoreFocus`). hold 중에는 host가
keyboard를 shell에 넘겨 두므로, 저장된 focus는 shell입니다. 그런데 host는 "window가
key이고(`isFocused()`, 즉 `isKeyWindow`) page가 보이면" 빚을 갚았습니다.
- window가 key는 되었지만 아직 main이 아닐 때 page가 보이면, host가 page에 keyboard를 주고 그
뒤의 main 전환이 shell focus를 되돌려 page가 keyboard를 잃습니다. 실패한 run마다
`browser.window_return page_focused:true`가 찍힌 뒤 857행이 5초 동안 false였던 것과
맞습니다(run 37360697791, 37372899600, 그리고 #511의 첫 run 37304329630).
- 반대로 page가 덮인 채 `focus`가 먼저 오고 page가 보인 뒤에야 key가 되면, key 전환에는 JS event가
없어 빚을 영영 갚지 않습니다. `window_return`이 없는 run 37357410267과 맞습니다.
- 고침(`desktop/src/main/browser.ts`): "window가 돌아왔다"를 `isFocused()`가 아니라
window 자신의 `blur`/`focus` event로 셉니다(`windowBack`). 빚은 `focus` event와
page의 보임 중 늦게 온 쪽에서 한 번 갚습니다. Electron의 되돌림은 언제나 `blur` 뒤의 `focus` 직전에
오므로, 갚은 뒤에 shell로 되돌아가지 않습니다.
- `browser.test.ts`: 두 경우를 한 test로 더했습니다(key지만 아직 돌아오지 않은 window에서 보인
page는 받지 않고 `focus`에서 한 번 받음, 덮인 채 돌아온 window에서 key 전에 보인 page는 받음). 기존
test 하나는 제목을 "window가 돌아온 뒤에만"으로 고쳤습니다.
- `docs/BROWSER_DISPLAYS.md`: 빚을 갚는 조건을 같은 말로 고쳤습니다.
- test(`browser.spec.ts`)는 바꾸지 않았습니다. 새 retry, timeout, sleep, allow는
없습니다.

## Review

- **판단해 주세요**: key 여부를 빚 조건에서 뺐습니다. main이 되었지만 아직 key가 아닌 순간에 page에
focus를 주면 그 page가 window의 first responder가 되고, 뒤따르는 key
전환(`OnWindowIsKeyChanged`)은 `SetActive`만 하고 focus를 되돌리지 않는다는 데
기댑니다(Electron 44 소스 확인).
- **조심해서 볼 파일**: `desktop/src/main/browser.ts` `windowBack` - `blur`마다
false, `focus`마다 true입니다. 빚이 없을 때는 아무것도 하지 않습니다.
- **질문**: 없음.

## Evidence

- **확인한 것**: `verify-web.sh desktop typecheck`, `desktop lint`, `desktop
test`(155 통과) 통과. `browser.test.ts` 14개 통과.
- **확인한 것 (planted defect)**: 빚 조건을 이전의 `this.window?.isFocused()`로 되돌리자
새 test가 "page가 window 돌아오기 전에 focus를 받음"으로 실패. 되돌리면 통과.
- **원인 근거**: 이 PR 전 실패 run 4개의 host log와 실패 행, Electron v44.4.5
소스(`electron_api_browser_window.cc`의 `OnWindowBlur`/`OnWindowFocus`,
`electron_ns_window_delegate.mm`의 main/key 알림, `native_window_mac.mm`의
`Focus`/`IsFocused`).
- **확인하지 못한 것**: `@needs-focus` test는 운영자의 창과 keyboard를 가로채므로 로컬에서 돌리지
않았습니다. CI desktop e2e lane 결과로만 확인합니다. 857행 실패는 run 몇 번에 한 번 꼴이라, 녹색 run
하나는 재발이 없다는 증거가 되지 못합니다.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant