Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(desktop): correctly await executeJavaScript for element focus restoration #5894

Closedmohamedmastouri-hue(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/5894/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* attemptPromise(
+ {
+ 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* () {
Thread on line 3045
macroscopeapp[bot](GitHub profile, opens in a new tab)commented

🟠 High preview/Manager.ts:3045

The focus-save/restore logic uses the hardcoded global window.__t3_restoreFocus to stash the previously focused element. If the page already defines that property, the save script unconditionally overwrites it and the cleanup script permanently deletes it, destroying the page's own value. Consider using a Symbol key or saving and restoring any pre-existing value so automation never clobbers a page-owned property.

🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/desktop/src/preview/Manager.ts around line 3045:

The focus-save/restore logic uses the hardcoded global `window.__t3_restoreFocus` to stash the previously focused element. If the page already defines that property, the save script unconditionally overwrites it and the cleanup script permanently deletes it, destroying the page's own value. Consider using a `Symbol` key or saving and restoring any pre-existing value so automation never clobbers a page-owned property.
+ if (previouslyFocused && previouslyFocused.id !== wc.id && !previouslyFocused.isDestroyed()) {
+ yield* attemptPromise(
+ {
+ operation: "automationPress.saveActiveElement",
+ tabId,
+ webContentsId: previouslyFocused.id,