Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(mobile): improve mobile split activation gate (#4868)

Peter Chinmanfab3755a1431
diff --git a/apps/web/src/components/app/split-layout/SplitLayout.tsx b/apps/web/src/components/app/split-layout/SplitLayout.tsx
index c9b2029d80..ea1273685f 100644
--- a/apps/web/src/components/app/split-layout/SplitLayout.tsx
+++ b/apps/web/src/components/app/split-layout/SplitLayout.tsx
@@ -197,7 +197,9 @@ function createSplitFocusTracker(props: {
}
let splitWithFocus: SplitId | undefined;
- for (const split of props.splits()) {
+ // Only visible splits may claim activation — the mobile background
+ // split is excluded and can never become active.
+ for (const split of props.splitManager.getVisibleSplits()) {
if (isElementInPanel(split.id, element)) {
splitWithFocus = split.id;
break;
diff --git a/apps/web/src/components/app/split-layout/layoutManager.ts b/apps/web/src/components/app/split-layout/layoutManager.ts
index 419cce39e9..875e48b030 100644
--- a/apps/web/src/components/app/split-layout/layoutManager.ts
+++ b/apps/web/src/components/app/split-layout/layoutManager.ts
@@ -848,6 +848,17 @@ export function createSplitLayout(
};
function activateSplit(id: SplitId) {
+ // Invariant: an excluded split (the mobile background split) can never
+ // become the active split. Promote it out of exclusion first.
+ const split = findSplitById(id);
+ if (split && isExcluded(split)) {
+ if (import.meta.env.DEV) {
+ console.warn(
+ `activateSplit: refusing to activate excluded split ${id}`
+ );
+ }
+ return;
+ }
const current = state.activeSplitId;
setState('lastActiveSplitId', current);
if (state.spotlightId && state.spotlightId !== id) {
diff --git a/apps/web/src/components/app/split-layout/mobile/MobileSplitContainer.tsx b/apps/web/src/components/app/split-layout/mobile/MobileSplitContainer.tsx
index dda9a0109f..6ef8d1f250 100644
--- a/apps/web/src/components/app/split-layout/mobile/MobileSplitContainer.tsx
+++ b/apps/web/src/components/app/split-layout/mobile/MobileSplitContainer.tsx
@@ -57,6 +57,10 @@ export function MobileSplitContainer(props: MobileSplitContainerProps) {
<div
class={motion.classForSlot(mobileSwipeLayout.fgIsSlotA())}
style={motion.styleForSlot(mobileSwipeLayout.fgIsSlotA())}
+ // The background slot is inert so focus (including programmatic
+ // autofocus in late-mounting content) can never land inside the
+ // invisible panel. Demoting a slot also blurs any focused child.
+ inert={!mobileSwipeLayout.fgIsSlotA()}
onTransitionEnd={(e) =>
motion.handleTransitionEnd(e, mobileSwipeLayout.fgIsSlotA())
}
@@ -89,6 +93,7 @@ export function MobileSplitContainer(props: MobileSplitContainerProps) {
<div
class={motion.classForSlot(!mobileSwipeLayout.fgIsSlotA())}
style={motion.styleForSlot(!mobileSwipeLayout.fgIsSlotA())}
+ inert={mobileSwipeLayout.fgIsSlotA()}
onTransitionEnd={(e) =>
motion.handleTransitionEnd(e, !mobileSwipeLayout.fgIsSlotA())
}
diff --git a/apps/web/src/components/app/split-layout/mobile/createMobileSwipeLayout.ts b/apps/web/src/components/app/split-layout/mobile/createMobileSwipeLayout.ts
index 356ec05b82..9a5fb646d9 100644
--- a/apps/web/src/components/app/split-layout/mobile/createMobileSwipeLayout.ts
+++ b/apps/web/src/components/app/split-layout/mobile/createMobileSwipeLayout.ts
@@ -144,8 +144,11 @@ export function createMobileSwipeLayout(
if (!preparedFgId) return;
batch(() => {
- splitManager.activateSplit(preparedFgId);
+ // Flip roles before activating: activateSplit refuses excluded
+ // (background) splits, and the prepared split stays excluded until
+ // the flip.
toggleFgSlot();
+ splitManager.activateSplit(preparedFgId);
});
}
@@ -171,8 +174,6 @@ export function createMobileSwipeLayout(
splitManager.removeSplit(currentFgId);
}
- splitManager.activateSplit(currentBgId);
-
const newBgHandle = newBgContent
? splitManager.createNewSplit({
content: newBgContent,
@@ -183,7 +184,11 @@ export function createMobileSwipeLayout(
: undefined;
setNewBgSlotId(newBgHandle?.id);
+ // Flip roles before activating: activateSplit refuses excluded
+ // (background) splits, and the promoted split stays excluded until
+ // the flip.
toggleFgSlot();
+ splitManager.activateSplit(currentBgId);
});
}
diff --git a/apps/web/src/components/app/split-layout/tests/layoutManager.test.ts b/apps/web/src/components/app/split-layout/tests/layoutManager.test.ts
index caab4aa709..b2f84d7792 100644
--- a/apps/web/src/components/app/split-layout/tests/layoutManager.test.ts
+++ b/apps/web/src/components/app/split-layout/tests/layoutManager.test.ts
@@ -6,6 +6,7 @@ import {
type SplitContent,
SplitEvent,
} from '../layoutManager';
+import { createMobileSwipeLayout } from '../mobile/createMobileSwipeLayout';
vi.mock('../componentRegistry', () => ({
resolveComponent: vi.fn((id: string, params: Record<string, string>) => ({
@@ -301,4 +302,61 @@ describe('layoutManager', () => {
});
});
});
+
+ describe('activation invariant', () => {
+ it('refuses to activate an excluded split', () => {
+ createRoot((dispose) => {
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
+ const manager = createSplitLayout(createMockOrchestrator(), [
+ { type: 'md', id: 'foreground' },
+ { type: 'md', id: 'background' },
+ ]);
+
+ const [fg, bg] = manager.splits();
+ manager.activateSplit(fg.id);
+ manager.setExclusionFilter((split) => split.id === bg.id);
+
+ manager.activateSplit(bg.id);
+ expect(manager.activeSplitId()).toBe(fg.id);
+
+ manager.setExclusionFilter(undefined);
+ manager.activateSplit(bg.id);
+ expect(manager.activeSplitId()).toBe(bg.id);
+
+ warn.mockRestore();
+ dispose();
+ });
+ });
+
+ it('keeps the promoted split active through mobile forward navigation and swipe back', () => {
+ createRoot((dispose) => {
+ const manager = createSplitLayout(createMockOrchestrator(), [
+ { type: 'md', id: 'list' },
+ ]);
+ const originalId = manager.splits()[0].id;
+ manager.activateSplit(originalId);
+
+ const swipeLayout = createMobileSwipeLayout(manager);
+
+ // Forward navigation goes through the interceptor; with no animation
+ // trigger registered it completes synchronously.
+ manager.openWithSplit(
+ { type: 'md', id: 'detail' },
+ { referredFrom: null }
+ );
+
+ const detailId = swipeLayout.fgIsSlotA()
+ ? swipeLayout.slotASplitId()
+ : swipeLayout.slotBSplitId();
+ expect(detailId).toBeDefined();
+ expect(detailId).not.toBe(originalId);
+ expect(manager.activeSplitId()).toBe(detailId);
+
+ swipeLayout.swipeBack();
+ expect(manager.activeSplitId()).toBe(originalId);
+
+ dispose();
+ });
+ });
+ });
});