Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(desktop): keep composer menus aligned

vastsae90f4fce25b3
diff --git a/apps/desktop/src/components/settings/AnchoredMenu.tsx b/apps/desktop/src/components/settings/AnchoredMenu.tsx
index 4e8f0d44c..9797c4be6 100644
--- a/apps/desktop/src/components/settings/AnchoredMenu.tsx
+++ b/apps/desktop/src/components/settings/AnchoredMenu.tsx
@@ -139,16 +139,18 @@ export function AnchoredMenu({
onClose();
return;
}
- const menuRect = menu.getBoundingClientRect();
+ // getBoundingClientRect includes the menu's entrance scale; anchoring must use its layout box.
+ const menuWidth = menu.offsetWidth;
+ const menuHeight = menu.offsetHeight;
const width = matchAnchorWidth ? anchorRect.width : undefined;
- const surfaceWidth = width ?? menuRect.width;
+ const surfaceWidth = width ?? menuWidth;
const maxLeft = Math.max(MARGIN, window.innerWidth - surfaceWidth - MARGIN);
const preferredLeft =
align === "end" ? anchorRect.right - surfaceWidth : anchorRect.left;
const left = Math.min(Math.max(MARGIN, preferredLeft), maxLeft);
const below = anchorRect.bottom + GAP;
- const above = anchorRect.top - menuRect.height - GAP;
- const maxTop = Math.max(MARGIN, window.innerHeight - menuRect.height - MARGIN);
+ const above = anchorRect.top - menuHeight - GAP;
+ const maxTop = Math.max(MARGIN, window.innerHeight - menuHeight - MARGIN);
const preferredTop = side === "top" ? above : below;
const fallbackTop = side === "top" ? below : above;
const preferredFits = preferredTop >= MARGIN && preferredTop <= maxTop;
diff --git a/scripts/e2e-composer-paste.mjs b/scripts/e2e-composer-paste.mjs
index 0ddd0e337..093ec48d1 100644
--- a/scripts/e2e-composer-paste.mjs
+++ b/scripts/e2e-composer-paste.mjs
@@ -25,7 +25,7 @@ try {
format: "iife",
jsx: "automatic",
loader: { ".woff": "file", ".woff2": "file", ".ttf": "file" },
- define: { "process.env.NODE_ENV": '"production"' },
+ define: { "import.meta.env.DEV": "false", "process.env.NODE_ENV": '"production"' },
alias: {
"@pi-desktop/i18n": join(root, "packages/i18n/src/index.ts"),
react: join(root, "apps/desktop/node_modules/react"),
diff --git a/scripts/e2e/composer-thinking-layout.tsx b/scripts/e2e/composer-thinking-layout.tsx
index 79224dc88..02bf65700 100644
--- a/scripts/e2e/composer-thinking-layout.tsx
+++ b/scripts/e2e/composer-thinking-layout.tsx
@@ -55,6 +55,39 @@ const settle = () => new Promise<void>((resolve) =>
requestAnimationFrame(() => requestAnimationFrame(() => resolve())),
);
+async function waitForMenuToSettle(menu: HTMLElement): Promise<void> {
+ let previousRect: DOMRect | undefined;
+ let previousTransform: string | undefined;
+ let stableFrames = 0;
+ for (let frame = 0; frame < 120; frame++) {
+ await new Promise<void>((resolve) => requestAnimationFrame(() => resolve()));
+ const rect = menu.getBoundingClientRect();
+ const transform = getComputedStyle(menu).transform;
+ const animating = menu.getAnimations().some(
+ (animation) => animation.pending || animation.playState === "running",
+ );
+ const untransformed = transform === "none";
+ const layoutMatches =
+ Math.abs(rect.width - menu.offsetWidth) <= 0.5 &&
+ Math.abs(rect.height - menu.offsetHeight) <= 0.5;
+ const stable =
+ layoutMatches &&
+ previousRect !== undefined &&
+ Math.abs(rect.left - previousRect.left) < 0.05 &&
+ Math.abs(rect.top - previousRect.top) < 0.05 &&
+ Math.abs(rect.width - previousRect.width) < 0.05 &&
+ Math.abs(rect.height - previousRect.height) < 0.05 &&
+ transform === previousTransform;
+ stableFrames = menu.classList.contains("is-open") && !animating && untransformed && stable
+ ? stableFrames + 1
+ : 0;
+ if (stableFrames >= 2) return;
+ previousRect = rect;
+ previousTransform = transform;
+ }
+ throw new Error("Composer reasoning menu did not settle after opening");
+}
+
declare global {
var composerThinkingLayoutProbe: () => Promise<unknown>;
var composerThinkingPointerProbe: {
@@ -133,10 +166,15 @@ globalThis.composerThinkingLayoutProbe = async () => {
element<HTMLButtonElement>(".composer-model-thinking-chip").click();
await settle();
const menu = element(".composer-model-thinking-menu");
- await Promise.all(menu.getAnimations().map((animation) => animation.finished));
- await settle();
- const initialLeft = menu.getBoundingClientRect().left;
- const initialTop = menu.getBoundingClientRect().top;
+ await waitForMenuToSettle(menu);
+ const initialMenuRect = menu.getBoundingClientRect();
+ const initialLeft = initialMenuRect.left;
+ const initialTop = initialMenuRect.top;
+ const initialTriggerRect = element<HTMLButtonElement>(".composer-model-thinking-chip").getBoundingClientRect();
+ const initialTriggerHeight = initialTriggerRect.height;
+ if (Math.abs(initialMenuRect.right - initialTriggerRect.right) > 0.05) {
+ failures.push(`${index}: opened menu did not align its right edge to the trigger (${initialMenuRect.right - initialTriggerRect.right}px)`);
+ }
for (const level of ["low", "omit", "high", "max", "off", "low"]) {
const tick = [...document.querySelectorAll<HTMLButtonElement>(".composer-thinking-tick")]
.find((button) => button.textContent === level);
@@ -151,7 +189,7 @@ globalThis.composerThinkingLayoutProbe = async () => {
if (!menu.classList.contains("is-open")) failures.push(`${index}: selection closed the menu`);
if (Math.abs(currentMenu.left - initialLeft) > 0.05) failures.push(`${index}/${level}: menu moved ${currentMenu.left - initialLeft}px`);
if (Math.abs(currentMenu.top - initialTop) > 0.05) failures.push(`${index}/${level}: menu moved vertically`);
- if (Math.abs(trigger.height - 28) > 0.05) failures.push(`${index}/${level}: trigger changed height`);
+ if (Math.abs(trigger.height - initialTriggerHeight) > 0.05) failures.push(`${index}/${level}: trigger changed height`);
if (trigger.right > wrapper.right + 0.05) failures.push(`${index}/${level}: trigger overflows its wrapper`);
measurements.push({ ...config, level, triggerRight: trigger.right, wrapperRight: wrapper.right, menuLeft: currentMenu.left });
}
diff --git a/scripts/e2e/provider-api-style.tsx b/scripts/e2e/provider-api-style.tsx
index 7dba83949..770d6190a 100644
--- a/scripts/e2e/provider-api-style.tsx
+++ b/scripts/e2e/provider-api-style.tsx
@@ -321,8 +321,6 @@ globalThis.providerApiStyleProbe = async () => {
const codexAccount = { ...fixture("openai_codex_responses"), id: "codex-account", name: "OpenAI OAuth", vendorKey: "openai-codex", type: "native", protocol: "openai", authKind: "oauth" } satisfies ProviderPublic;
let savedCodexAccount: VendorAccountForm | undefined;
flushSync(() => root.render(<I18nextProvider i18n={i18n}><VendorAccountDialog provider={codexAccount} initialName={codexAccount.name} onClose={() => { closes++; }} onSave={(form) => { savedCodexAccount = structuredClone(form); }} saving={false} /></I18nextProvider>));
- const accountAdvanced = document.querySelector<HTMLButtonElement>(".provider-chosen-advanced-toggle");
- if (accountAdvanced?.getAttribute("aria-expanded") === "false") click(accountAdvanced);
await pause(650);
// The account editor opens straight on the model panel (D625): the
// per-model controls sit behind the row's own Advanced disclosure.
diff --git a/scripts/e2e/sidebar-row-states.mjs b/scripts/e2e/sidebar-row-states.mjs
index 35f8d00e4..453d463e0 100644
--- a/scripts/e2e/sidebar-row-states.mjs
+++ b/scripts/e2e/sidebar-row-states.mjs
@@ -196,12 +196,12 @@ export async function checkSidebarRowStates({ cdp, check, waitFor, seed }) {
const chatShell = document.querySelector('.app-chat-shell');
const sidebar = chatShell?.querySelector('.sidebar');
return {
- hidden: chatShell?.hidden === true && chatShell.inert,
+ hiddenAndInert: chatShell?.hidden === true && chatShell.inert === true,
sidebarRetained: sidebar?.isConnected === true,
};
})()`);
check(
- hiddenChatState.hidden && hiddenChatState.sidebarRetained,
+ hiddenChatState.hiddenAndInert && hiddenChatState.sidebarRetained,
`${theme} settings hides the mounted chat and sidebar`,
JSON.stringify({ hiddenChatState, selectedIds: await selectedIds() }),
);