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(splits): use mergeHistory flag for url sync correctly (#4426)

Seamusc1e745c281bd
diff --git a/js/app/packages/app/component/split-layout/SplitLayout.tsx b/js/app/packages/app/component/split-layout/SplitLayout.tsx
index 18f2880171..daead312f3 100644
--- a/js/app/packages/app/component/split-layout/SplitLayout.tsx
+++ b/js/app/packages/app/component/split-layout/SplitLayout.tsx
@@ -52,6 +52,29 @@ function getParentSplitId(element: Element | null) {
return splitId as SplitId;
}
+function sameSplitContentIdentity(a: SplitContent, b: SplitContent) {
+ return a.type === b.type && a.id === b.id;
+}
+
+function getUrlSyncAffectedSplit(
+ splitManager: SplitManager,
+ currentPairs: SplitContent[],
+ nextPairs: SplitContent[]
+) {
+ const changedIndex = nextPairs.findIndex(
+ (nextPair, index) =>
+ !currentPairs[index] ||
+ !sameSplitContentIdentity(currentPairs[index], nextPair)
+ );
+
+ if (changedIndex < 0) return undefined;
+
+ const affectedPair = nextPairs[changedIndex];
+ return splitManager
+ .splits()
+ .find((split) => sameSplitContentIdentity(split.content, affectedPair));
+}
+
/**
* Creates an effect that syncs the layout manager with the URL.
*
@@ -73,8 +96,17 @@ function createLayoutUrlSync(
createEffect(
on([() => splitManager.getUrlSegments().join('/')], () => {
if (urlLayoutDrift()) {
+ const nextUrlSegments = splitManager.getUrlSegments();
+ const nextPairs = decodePairs(nextUrlSegments);
+ const affectedSplit = getUrlSyncAffectedSplit(
+ splitManager,
+ decodedPairs(),
+ nextPairs
+ );
+ const replace = affectedSplit?.lastNavigationCause === 'replace';
+
// Flush the state to the url
- navigate(`/${splitManager.getUrlSegments().join('/')}`);
+ navigate(`/${nextUrlSegments.join('/')}`, { replace });
}
})
);
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 f924fcf39b..0abf5f0d8c 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,11 @@
import type { BlockOrchestrator } from '@core/orchestrator';
import { createRoot } from 'solid-js';
import { beforeAll, describe, expect, it, vi } from 'vitest';
-import { createSplitLayout, type SplitContent } from '../layoutManager';
+import {
+ createSplitLayout,
+ type SplitContent,
+ SplitEvent,
+} from '../layoutManager';
vi.mock('../componentRegistry', () => ({
resolveComponent: vi.fn((id: string, params: Record<string, string>) => ({
@@ -155,6 +159,32 @@ describe('layoutManager', () => {
});
});
+ describe('split history', () => {
+ it('marks mergeHistory content changes as replace navigation', () => {
+ createRoot((dispose) => {
+ const manager = createSplitLayout(createMockOrchestrator(), [
+ { type: 'component', id: 'inbox' },
+ ]);
+
+ const split = manager.getSplit(manager.splits()[0].id)!;
+
+ split.replace({
+ next: { type: 'md', id: 'created-doc' },
+ mergeHistory: true,
+ });
+
+ expect(manager.events()).toMatchObject({
+ type: SplitEvent.ContentChange,
+ cause: 'replace',
+ newContent: { type: 'md', id: 'created-doc' },
+ previousContent: { type: 'component', id: 'inbox' },
+ });
+
+ dispose();
+ });
+ });
+ });
+
describe('indexed insertion', () => {
it('creates a split at the requested index', () => {
createRoot((dispose) => {