Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(desktop): preserve active element during automation press #5874

Closedmohamedmastouri-hue(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/5874/headopened View on GitHub

Showing 1 changed file with 24 additions and 0 deletions.

x
0 of 1 viewed, 1 left
24 additions and 0 deletionsapps/desktop/src/preview/Manager.tsModified
View file
@@ -3024,6 +3024,17 @@
() => previouslyFocused.focus(),
).pipe(Effect.ignore);
+ 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 @@
// changing which thread is mounted in the UI. Restore the previous renderer
// after dispatch so automation never leaves the app's input focus behind.
yield* Effect.gen(function* () {
+ if (previouslyFocused && previouslyFocused.id !== wc.id && !previouslyFocused.isDestroyed()) {
+ yield* attempt(
Thread on line 3047
macroscopeapp[bot](GitHub profile, opens in a new tab)commented

🟡 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,