Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(editor): a shut drawer was 384px of page nobody could scroll back from

esengine381dee630c62
diff --git a/desktop/src/components/dialogFocus.ts b/desktop/src/components/dialogFocus.ts
index a7ca8ee65..f036ea214 100644
--- a/desktop/src/components/dialogFocus.ts
+++ b/desktop/src/components/dialogFocus.ts
@@ -40,7 +40,7 @@ export function useDialogFocus(ref: RefObject<HTMLElement | null>, active = true
// Seed focus inside — unless the shell already autofocused its own field
// (command palettes / settings focus their search input on mount).
- if (!container.contains(doc.activeElement)) container.focus();
+ if (!container.contains(doc.activeElement)) container.focus({ preventScroll: true });
// Trap Tab: cycle within the container; recapture if focus escaped.
const onKey = (e: KeyboardEvent) => {
@@ -48,7 +48,7 @@ export function useDialogFocus(ref: RefObject<HTMLElement | null>, active = true
const items = focusables(container);
if (items.length === 0) {
e.preventDefault();
- container.focus();
+ container.focus({ preventScroll: true });
return;
}
const first = items[0];
@@ -57,17 +57,20 @@ export function useDialogFocus(ref: RefObject<HTMLElement | null>, active = true
const inside = active instanceof HTMLElement && container.contains(active);
if (e.shiftKey && (!inside || active === first)) {
e.preventDefault();
- last.focus();
+ last.focus({ preventScroll: true });
} else if (!e.shiftKey && (!inside || active === last)) {
e.preventDefault();
- first.focus();
+ first.focus({ preventScroll: true });
}
};
win.addEventListener('keydown', onKey, true);
return () => {
win.removeEventListener('keydown', onKey, true);
// Hand focus back to whoever opened the dialog (if still in the DOM).
- if (opener?.isConnected) opener.focus();
+ // Never SCROLLING to it: a dialog that has just closed may still hold
+ // focus somewhere off screen, and the default focus() drags the nearest
+ // scrollable ancestor over to it — which moved the whole editor.
+ if (opener?.isConnected) opener.focus({ preventScroll: true });
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [active]);
diff --git a/desktop/src/theme/chrome.css b/desktop/src/theme/chrome.css
index aafd11e51..64723dfad 100644
--- a/desktop/src/theme/chrome.css
+++ b/desktop/src/theme/chrome.css
@@ -269,6 +269,14 @@
opacity: 0;
pointer-events: none;
transition: opacity var(--t) var(--e-out);
+ /* A CLOSED drawer is parked off the edge (translateX/Y(100%)) and is still in
+ the layout, so without this it hands the page 384px of horizontal overflow
+ (and the bottom one 379px of vertical) for as long as it is shut — which is
+ nearly always. `clip`, not `hidden`: hidden merely has no scrollbar and can
+ still be scrolled BY CODE, and a focus() handing itself back on close did
+ exactly that, sliding the whole editor sideways with no way to slide it
+ back. Clip creates no scroll container at all. */
+ overflow: clip;
}
.scrim.open { opacity: 1; pointer-events: auto; }
.scrim--bottom { align-items: flex-end; }
diff --git a/desktop/tests/overlay-clip.test.ts b/desktop/tests/overlay-clip.test.ts
new file mode 100644
index 000000000..934dd775d
--- /dev/null
+++ b/desktop/tests/overlay-clip.test.ts
@@ -0,0 +1,48 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file A parked drawer must not be somewhere the page can scroll to.
+ *
+ * Reported as "closing the agent shifts the whole editor left". A shut drawer is
+ * still in the layout, parked off the edge by `translateX(100%)` — 384px of
+ * horizontal overflow for as long as it is shut, which is nearly always, and the
+ * bottom one 379px of vertical. `overflow: hidden` is not the fix and was not
+ * the state: hidden merely removes the scrollbar and can still be scrolled BY
+ * CODE, which is what the focus handed back on close did — sliding the editor
+ * sideways with no scrollbar left to slide it back.
+ *
+ * Asserted against the stylesheet because the rule IS the fix, and nothing else
+ * in the suite renders a DOM to catch it going away.
+ */
+import { describe, it, expect } from 'vitest';
+import { readFileSync } from 'node:fs';
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';
+
+const HERE = path.dirname(fileURLToPath(import.meta.url));
+const CHROME_CSS = readFileSync(path.join(HERE, '..', 'src', 'theme', 'chrome.css'), 'utf8');
+
+/** The `.scrim { ... }` block — the drawers' own container. */
+function scrimBlock(): string {
+ const at = CHROME_CSS.search(/^\.scrim\s*\{/m);
+ expect(at, '.scrim has no rule in chrome.css').toBeGreaterThanOrEqual(0);
+ return CHROME_CSS.slice(at, CHROME_CSS.indexOf('}', at));
+}
+
+describe('the drawer container clips what it parks', () => {
+ it('clips, so a shut drawer adds no overflow to the page', () => {
+ expect(scrimBlock()).toMatch(/overflow:\s*clip\b/);
+ });
+
+ // `hidden` looks like it works — the scrollbar goes — and leaves the failure
+ // fully intact, because a hidden box is still programmatically scrollable.
+ it('does not settle for hidden, which code can still scroll', () => {
+ expect(scrimBlock()).not.toMatch(/overflow:\s*hidden\b/);
+ });
+
+ // Both drawers park off an edge; clipping one axis leaves the other's 379px.
+ it('parks both drawers outside the box it clips', () => {
+ expect(CHROME_CSS).toMatch(/scrim--bottom.*\{[^}]*transform:\s*translateY\(100%\)/s);
+ expect(CHROME_CSS).toMatch(/scrim--right.*\{[^}]*transform:\s*translateX\(100%\)/s);
+ });
+});