fix(desktop): preserve active element during automation press #5874
Closed
mohamedmastouri-hue(GitHub profile, opens in a new tab)wants to merge 1 commit into
main fromrefs/pull/5874/head·opened View on GitHubShowing 1 changed file with 24 additions and 0 deletions.
x
@@ -3024,6 +3024,17 @@
+ yield* attempt(
+ {
+ operation: "automationPress.restoreActiveElement",
+ tabId,
+ webContentsId: previouslyFocused.id,
+ },
+ () =>
+ previouslyFocused.executeJavaScript(
+ `if (window.__t3_restoreFocus && typeof window.__t3_restoreFocus.focus === 'function') { window.__t3_restoreFocus.focus(); delete window.__t3_restoreFocus; }`,
+ ),
+ ).pipe(Effect.ignore);
@@ -3032,6 +3043,19 @@
+ if (previouslyFocused && previouslyFocused.id !== wc.id && !previouslyFocused.isDestroyed()) {
+ yield* attempt(
Thread on line 3047
🟡 Medium preview/Manager.ts:3047
The two new executeJavaScript calls are wrapped with attempt instead of attemptPromise, so their returned Promises are never awaited. The save at automationPress.saveActiveElement can resolve after wc.focus() has already moved focus, and the restore at automationPress.restoreActiveElement can finish after the teardown effect returns — with any rejection escaping Effect.ignore because the unawaited Promise rejects outside the effect's error handling. Use attemptPromise for both calls so they are awaited within the effect.
🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/desktop/src/preview/Manager.ts around line 3047:
The two new `executeJavaScript` calls are wrapped with `attempt` instead of `attemptPromise`, so their returned Promises are never awaited. The save at `automationPress.saveActiveElement` can resolve after `wc.focus()` has already moved focus, and the restore at `automationPress.restoreActiveElement` can finish after the teardown effect returns — with any rejection escaping `Effect.ignore` because the unawaited Promise rejects outside the effect's error handling. Use `attemptPromise` for both calls so they are awaited within the effect.
+ {
+ operation: "automationPress.saveActiveElement",
+ tabId,
+ webContentsId: previouslyFocused.id,