fix(client): use requestAnimationFrame to focus editor on mount in Firefox (#66405)

This commit is contained in:
Ragini Pandey
2026-03-13 18:04:40 +05:30
committed by GitHub
parent c70d7f8549
commit 52e2141f4a
2 changed files with 10 additions and 2 deletions
@@ -1115,10 +1115,12 @@ const Editor = (props: EditorProps): JSX.Element => {
if (!editor || !canFocusOnMountRef.current) return; if (!editor || !canFocusOnMountRef.current) return;
if (!props.usesMultifileEditor) { if (!props.usesMultifileEditor) {
// Only one editor? Focus it. // Only one editor? Focus it.
editor.focus(); // Use requestAnimationFrame to ensure focus works in browsers like
// Firefox that have stricter programmatic focus policies.
requestAnimationFrame(() => editor.focus());
canFocusOnMountRef.current = false; canFocusOnMountRef.current = false;
} else if (hasEditableRegion()) { } else if (hasEditableRegion()) {
editor.focus(); requestAnimationFrame(() => editor.focus());
canFocusOnMountRef.current = false; canFocusOnMountRef.current = false;
} }
} }
+6
View File
@@ -23,6 +23,12 @@ test.use({
viewport: { width: 1080, height: 720 } viewport: { width: 1080, height: 720 }
}); });
test('Editor is focused on load', async ({ page }) => {
await page.goto(workshopChallengeUrl);
await expect(getEditors(page)).toBeFocused();
});
test('Clicking "Check Your Code" reveals failing feedback', async ({ test('Clicking "Check Your Code" reveals failing feedback', async ({
page page
}) => { }) => {