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: history not loading (#4877)

Wolf Mermelsteinf5864dad9821
diff --git a/apps/web/src/components/app/side-panel/SidePanel.tsx b/apps/web/src/components/app/side-panel/SidePanel.tsx
index 5c39f257bc..354c791bea 100644
--- a/apps/web/src/components/app/side-panel/SidePanel.tsx
+++ b/apps/web/src/components/app/side-panel/SidePanel.tsx
@@ -110,6 +110,7 @@ function Layout(props: ParentProps<{ defaultOpen?: boolean }>) {
toggle,
isNarrow,
setOpenSectionIds: setOpenIds,
+ openSectionIds: openIds,
};
return (
@@ -363,6 +364,7 @@ function useSidePanel() {
isNarrow: ctx.isNarrow,
hasSections: ctx.hasSections,
setOpenSectionIds: ctx.setOpenSectionIds,
+ openSectionIds: ctx.openSectionIds,
};
}
diff --git a/apps/web/src/components/app/side-panel/context.ts b/apps/web/src/components/app/side-panel/context.ts
index 2fbf441e9f..9ab3481375 100644
--- a/apps/web/src/components/app/side-panel/context.ts
+++ b/apps/web/src/components/app/side-panel/context.ts
@@ -29,6 +29,8 @@ export type SidePanelContextType = {
toggle: () => void;
/** Set which section IDs are expanded in the accordion. */
setOpenSectionIds: (ids: string[]) => void;
+ /** Which section IDs are currently expanded in the accordion. */
+ openSectionIds: Accessor<string[]>;
/**
* True when the layout is mobile or narrower than the split threshold.
* In this mode the side panel renders as a full-screen overlay rather than
diff --git a/apps/web/src/features/block-md/component/sidepanel/MarkdownSidePanelSections.tsx b/apps/web/src/features/block-md/component/sidepanel/MarkdownSidePanelSections.tsx
index dd976157e6..1f047dbd54 100644
--- a/apps/web/src/features/block-md/component/sidepanel/MarkdownSidePanelSections.tsx
+++ b/apps/web/src/features/block-md/component/sidepanel/MarkdownSidePanelSections.tsx
@@ -146,6 +146,16 @@ function HistorySectionContent() {
sidePanel?.setOpenSectionIds(['history']);
}
});
+
+ // Discover whether history exists (to choose between the empty state and
+ // the scrubber) once the user actually expands this accordion section —
+ // nothing inside the section can trigger the load itself, since the
+ // scrubber and "Show activity" toggle only render once sessions exist.
+ createEffect(() => {
+ if (sidePanel?.openSectionIds().includes('history')) {
+ history.requestLoad();
+ }
+ });
const isShowingSessions = () => history.isOpen() || showSessions();
const totalEdits = createMemo(() => {
diff --git a/apps/web/src/features/block-md/history/HistoryContext.tsx b/apps/web/src/features/block-md/history/HistoryContext.tsx
index 683aa42e23..594ac7b411 100644
--- a/apps/web/src/features/block-md/history/HistoryContext.tsx
+++ b/apps/web/src/features/block-md/history/HistoryContext.tsx
@@ -39,6 +39,7 @@ type HistoryContextValue = {
open: () => void;
enter: (at?: Date) => void;
exit: () => void;
+ requestLoad: () => void;
sessions: Accessor<readonly HistorySession[]>;
loading: { sessions: Accessor<boolean>; doc: Accessor<boolean> };
checkoutAt: (ms: number) => SerializedEditorState | null;
@@ -65,6 +66,8 @@ export function HistoryProvider(props: {
const [diffSession, setDiffSession] = createSignal<HistorySession | null>(
null
);
+ const [shouldLoad, setShouldLoad] = createSignal(false);
+ const requestLoad = () => setShouldLoad(true);
const open = () => setIsOpen(true);
@@ -95,7 +98,7 @@ export function HistoryProvider(props: {
// local scrubbing from it. The full snapshot (not updates) is required so
// getAllChanges() carries the per-change timestamp metadata.
const [historyDoc] = createResource(
- () => (isOpen() ? props.documentId() : undefined),
+ () => (isOpen() || shouldLoad() ? props.documentId() : undefined),
async (documentId) => {
const result = await syncServiceClient.getSnapshot({ documentId });
if (result.isErr()) throw new Error(String(result.error));
@@ -107,7 +110,7 @@ export function HistoryProvider(props: {
// Peer -> user mapping for labelling sessions; lightweight JSON.
const peerMap = useDocumentPeersQuery(() =>
- isOpen() ? props.documentId() : ''
+ isOpen() || shouldLoad() ? props.documentId() : ''
);
// AI peers are recognizable from the peer id alone (reserved block) and all
@@ -219,6 +222,7 @@ export function HistoryProvider(props: {
open,
enter,
exit,
+ requestLoad,
sessions,
loading: {
sessions: () => historyDoc() == null || peerMap.isPending,