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(md,suspense): add non suspense triggering reads to md HistoryContext (#4945)

Seamus319fc5476a7a
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 1f047dbd54..63bf23a2c5 100644
--- a/apps/web/src/features/block-md/component/sidepanel/MarkdownSidePanelSections.tsx
+++ b/apps/web/src/features/block-md/component/sidepanel/MarkdownSidePanelSections.tsx
@@ -165,58 +165,69 @@ function HistorySectionContent() {
});
return (
- <Show
- when={
- !history.loading.sessions() && totalEdits() > 1 && history.sessions()
- }
- fallback={<p class="text-xs text-ink-muted">No history yet</p>}
- >
- {(sessions) => (
- <div class="hidden min-w-0 overflow-hidden md:block">
- <HistoryScrubber compact />
- <Show when={sessions().length > 0}>
- <div class="mt-3 min-w-0 border-edge-muted border-t pt-2">
- <button
- type="button"
- aria-expanded={isShowingSessions()}
- class="flex w-full items-center gap-1.5 rounded-md px-1 py-1 text-ink-muted text-xs hover:bg-hover hover:text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40"
- onClick={() => {
- history.enter();
- setShowSessions(true);
- }}
- >
- <CaretRightIcon
- class={cn(
- 'size-3 shrink-0 transition-transform duration-90',
- isShowingSessions() && 'rotate-90'
- )}
- />
- <span>
- {isShowingSessions() ? 'Activity' : 'Show activity'}
- </span>
- </button>
- <Show when={isShowingSessions()}>
- <HistorySessionList
- sessions={sessions()}
- selectedAt={history.selectedAt}
- onSelect={history.enter}
- onViewSessionDiff={(session) => {
- if (history.diff.session()?.startMs === session.startMs) {
- history.diff.clear();
- } else {
- history.diff.view(session);
- }
+ <Show when={!history.loading.sessions()} fallback={<HistorySkeleton />}>
+ <Show
+ when={totalEdits() > 1 && history.sessions()}
+ fallback={<p class="text-xs text-ink-muted">No history yet</p>}
+ >
+ {(sessions) => (
+ <div class="hidden min-w-0 overflow-hidden md:block">
+ <HistoryScrubber compact />
+ <Show when={sessions().length > 0}>
+ <div class="mt-3 min-w-0 border-edge-muted border-t pt-2">
+ <button
+ type="button"
+ aria-expanded={isShowingSessions()}
+ class="flex w-full items-center gap-1.5 rounded-md px-1 py-1 text-ink-muted text-xs hover:bg-hover hover:text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40"
+ onClick={() => {
+ history.enter();
+ setShowSessions(true);
}}
- />
- </Show>
- </div>
- </Show>
- </div>
- )}
+ >
+ <CaretRightIcon
+ class={cn(
+ 'size-3 shrink-0 transition-transform duration-90',
+ isShowingSessions() && 'rotate-90'
+ )}
+ />
+ <span>
+ {isShowingSessions() ? 'Activity' : 'Show activity'}
+ </span>
+ </button>
+ <Show when={isShowingSessions()}>
+ <HistorySessionList
+ sessions={sessions()}
+ selectedAt={history.selectedAt}
+ onSelect={history.enter}
+ onViewSessionDiff={(session) => {
+ if (history.diff.session()?.startMs === session.startMs) {
+ history.diff.clear();
+ } else {
+ history.diff.view(session);
+ }
+ }}
+ />
+ </Show>
+ </div>
+ </Show>
+ </div>
+ )}
+ </Show>
</Show>
);
}
+function HistorySkeleton() {
+ return (
+ <div
+ aria-hidden="true"
+ class="hidden min-w-0 flex-col gap-2.5 overflow-hidden md:flex"
+ >
+ <div class="skeleton-shimmer h-12 w-full rounded-md bg-ink/3" />
+ </div>
+ );
+}
+
// ─────────────────────────────────────────────────────────────────────────────
// Sharing Section (snippets)
// ─────────────────────────────────────────────────────────────────────────────
diff --git a/apps/web/src/features/block-md/history/HistoryContext.tsx b/apps/web/src/features/block-md/history/HistoryContext.tsx
index 594ac7b411..3180206b3a 100644
--- a/apps/web/src/features/block-md/history/HistoryContext.tsx
+++ b/apps/web/src/features/block-md/history/HistoryContext.tsx
@@ -121,10 +121,22 @@ export function HistoryProvider(props: {
? MACRO_AGENT_BOT_ID
: (peers.get(peer) ?? 'unknown');
+ // Non-suspending reads of the loaded doc and peer map. Reading the resource
+ // (`historyDoc()`) or the query.data while they're still pending bubbles
+ // a Suspense trigger. This Provider is mounted above places where a simple
+ // suspense on the history UI would work.
+ const loadedDoc = (): LoroDoc | undefined =>
+ historyDoc.state === 'ready' || historyDoc.state === 'refreshing'
+ ? historyDoc.latest
+ : undefined;
+ const loadedPeers = (): Map<string, string> | undefined =>
+ peerMap.isSuccess ? peerMap.data : undefined;
+
// One stable useDisplayName per unique userId — batched into a single fetch.
- const uniqueUserIds = createMemo(() =>
- peerMap.data ? [...new Set(peerMap.data.values())] : []
- );
+ const uniqueUserIds = createMemo(() => {
+ const peers = loadedPeers();
+ return peers ? [...new Set(peers.values())] : [];
+ });
const userEntries = mapArray(uniqueUserIds, (userId) => {
const [displayName] = useDisplayName(tryMacroId(userId), {
emailFallback: 'local-part',
@@ -138,18 +150,18 @@ export function HistoryProvider(props: {
color: userColor(userId),
};
const userByPeer = (peerId: string): HistoryUser =>
- userById(resolvePeerUser(peerMap.data ?? new Map(), peerId));
+ userById(resolvePeerUser(loadedPeers() ?? new Map(), peerId));
const historyIndex = createMemo(() => {
- const doc = historyDoc();
+ const doc = loadedDoc();
return doc ? buildTimestampIndex(doc) : null;
});
// Sessions derived locally from the oplog: one edit event per change, grouped
// per user.
const sessions = createMemo<readonly HistorySession[]>(() => {
- const doc = historyDoc();
- const peers = peerMap.data;
+ const doc = loadedDoc();
+ const peers = loadedPeers();
if (!doc || !peers) return [];
const events: { userId: string; tMs: number }[] = [];
@@ -197,8 +209,8 @@ export function HistoryProvider(props: {
if (!before.root.children?.length || !after.root.children?.length)
return null;
try {
- const doc = historyDoc();
- const peers = peerMap.data;
+ const doc = loadedDoc();
+ const peers = loadedPeers();
const whoMap =
doc && peers
? buildWhoMap(doc, (peer) => resolvePeerUser(peers, peer))
@@ -225,8 +237,8 @@ export function HistoryProvider(props: {
requestLoad,
sessions,
loading: {
- sessions: () => historyDoc() == null || peerMap.isPending,
- doc: () => historyDoc() == null,
+ sessions: () => loadedDoc() == null || peerMap.isPending,
+ doc: () => loadedDoc() == null,
},
checkoutAt,
versionIdAt,