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(layout): registration time of splits during reconcile (#478)

teo3abf3703468d
diff --git a/js/app/packages/app/component/split-layout/SplitLayout.tsx b/js/app/packages/app/component/split-layout/SplitLayout.tsx
index dfc7eac17d..2c08309040 100644
--- a/js/app/packages/app/component/split-layout/SplitLayout.tsx
+++ b/js/app/packages/app/component/split-layout/SplitLayout.tsx
@@ -317,7 +317,7 @@ export function SplitLayoutContainer(props: SplitLayoutContainerProps) {
>
<For each={ids()}>
{(id, index) => (
- <Resize.Panel id={id} minSize={400}>
+ <Resize.Panel id={id} minSize={400} index={index()}>
<SplitPanel
split={splits()[index()]!}
handle={splitManager.getSplit(id)!}
diff --git a/js/app/packages/app/component/split-layout/layoutManager.ts b/js/app/packages/app/component/split-layout/layoutManager.ts
index 7134ce1d01..342620576e 100644
--- a/js/app/packages/app/component/split-layout/layoutManager.ts
+++ b/js/app/packages/app/component/split-layout/layoutManager.ts
@@ -660,8 +660,12 @@ export function createSplitLayout(
if (!changed) return;
+ const originalSplits = [...state.splits];
+
const lookup = (type: BlockName, id: string) =>
- state.splits.find((s) => s.content.type === type && s.content.id === id);
+ originalSplits.find(
+ (s) => s.content.type === type && s.content.id === id
+ );
const splitsToRemove = [
// just remount all the components
diff --git a/js/app/packages/app/component/split-layout/tests/layoutManager.test.ts b/js/app/packages/app/component/split-layout/tests/layoutManager.test.ts
index e8b377f195..6c5e4954f0 100644
--- a/js/app/packages/app/component/split-layout/tests/layoutManager.test.ts
+++ b/js/app/packages/app/component/split-layout/tests/layoutManager.test.ts
@@ -1,7 +1,7 @@
import type { BlockOrchestrator } from '@core/orchestrator';
import { createRoot } from 'solid-js';
import { beforeAll, describe, expect, it, vi } from 'vitest';
-import { createSplitLayout } from '../layoutManager';
+import { createSplitLayout, type SplitContent } from '../layoutManager';
vi.mock('../componentRegistry.tsx', () => ({
resolveComponent: vi.fn((id: string, params: Record<string, string>) => ({
@@ -83,5 +83,39 @@ describe('layoutManager', () => {
dispose();
});
});
+
+ it('should preserve ordering when reconciling back to previous state (browser back)', () => {
+ createRoot((dispose) => {
+ const ORIGINAL_SPLITS = [
+ { type: 'md', id: 'test-md-0' },
+ { type: 'md', id: 'test-md-1' },
+ { type: 'md', id: 'test-md-2' },
+ ] satisfies SplitContent[];
+
+ const NEW_SPLITS = [
+ { type: 'md', id: 'test-md-0' },
+ { type: 'md', id: 'test-md-3' },
+ { type: 'md', id: 'test-md-2' },
+ ] satisfies SplitContent[];
+
+ const manager = createSplitLayout(
+ createMockOrchestrator(),
+ ORIGINAL_SPLITS
+ );
+ expect(manager.splits()).toHaveLength(3);
+ expect(manager.splits().map((s) => s.content)).toEqual(ORIGINAL_SPLITS);
+
+ manager.reconcile(NEW_SPLITS);
+ expect(manager.splits()).toHaveLength(3);
+ expect(manager.splits().map((s) => s.content)).toEqual(NEW_SPLITS);
+
+ manager.reconcile(ORIGINAL_SPLITS);
+
+ expect(manager.splits()).toHaveLength(3);
+ expect(manager.splits().map((s) => s.content)).toEqual(ORIGINAL_SPLITS);
+
+ dispose();
+ });
+ });
});
});
diff --git a/js/app/packages/core/component/Resize/Resize.tsx b/js/app/packages/core/component/Resize/Resize.tsx
index bb041cc750..37d698425a 100644
--- a/js/app/packages/core/component/Resize/Resize.tsx
+++ b/js/app/packages/core/component/Resize/Resize.tsx
@@ -83,8 +83,11 @@ function Zone(props: ParentProps<ZoneProps>) {
panels: [],
});
- function register(config: PanelConfig) {
- solver.addPanel({ ...config, minSize: config?.minSize ?? minSize() });
+ function register(config: PanelConfig, index?: number) {
+ solver.addPanel(
+ { ...config, minSize: config?.minSize ?? minSize() },
+ index
+ );
}
function unregister(id: PanelId) {
@@ -183,6 +186,8 @@ type PanelProps = {
maxSize?: number;
collapsed?: () => boolean;
hidden?: () => boolean;
+ /** The index position for this panel in the layout order */
+ index?: number;
persistent?: boolean;
};
@@ -218,11 +223,14 @@ function Panel(props: ParentProps<PanelProps>) {
onMount(() => {
if (props.collapsed?.() === false) return;
- ctx.register({
- id: props.id,
- minSize: props.minSize,
- maxSize: props.maxSize ?? Infinity,
- });
+ ctx.register(
+ {
+ id: props.id,
+ minSize: props.minSize,
+ maxSize: props.maxSize ?? Infinity,
+ },
+ props.index
+ );
});
createEffect(() => {
@@ -231,11 +239,14 @@ function Panel(props: ParentProps<PanelProps>) {
if (collapsed) {
ctx.unregister(props.id);
} else {
- ctx.register({
- id: props.id,
- minSize: props.minSize,
- maxSize: props.maxSize ?? Infinity,
- });
+ ctx.register(
+ {
+ id: props.id,
+ minSize: props.minSize,
+ maxSize: props.maxSize ?? Infinity,
+ },
+ props.index
+ );
}
});
@@ -253,11 +264,14 @@ function Panel(props: ParentProps<PanelProps>) {
if (hidden) {
ctx.unregister(props.id);
} else {
- ctx.register({
- id: props.id,
- minSize: props.minSize,
- maxSize: props.maxSize ?? Infinity,
- });
+ ctx.register(
+ {
+ id: props.id,
+ minSize: props.minSize,
+ maxSize: props.maxSize ?? Infinity,
+ },
+ props.index
+ );
}
}
});
diff --git a/js/app/packages/core/component/Resize/solver.ts b/js/app/packages/core/component/Resize/solver.ts
index 5adfc04bcb..cd8cac0aaf 100644
--- a/js/app/packages/core/component/Resize/solver.ts
+++ b/js/app/packages/core/component/Resize/solver.ts
@@ -10,7 +10,7 @@ import type { LayoutResult, Panel, PanelConfig, PanelId } from './types';
export type ResizeSolver = {
readonly direction: 'horizontal' | 'vertical';
- addPanel: (panel: PanelConfig) => void;
+ addPanel: (panel: PanelConfig, index?: number) => void;
dropPanel: (id: PanelId) => void;
solve: () => LayoutResult;
reset: () => void;
diff --git a/js/app/packages/core/component/Resize/types.ts b/js/app/packages/core/component/Resize/types.ts
index f2e3f04958..191741a80b 100644
--- a/js/app/packages/core/component/Resize/types.ts
+++ b/js/app/packages/core/component/Resize/types.ts
@@ -34,7 +34,7 @@ export type LayoutResult = {
export type ResizeZoneCtx = {
direction: 'horizontal' | 'vertical';
- register: (panel: PanelConfig) => void;
+ register: (panel: PanelConfig, index?: number) => void;
unregister: (id: PanelId) => void;
gutterSize: () => number;
size: () => number;