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(channels): initial scroll race condition (#2447)

teo16b4afd7d9d5
diff --git a/js/app/packages/channel/Channel/Channel.tsx b/js/app/packages/channel/Channel/Channel.tsx
index d32debcc54..35929eadfc 100644
--- a/js/app/packages/channel/Channel/Channel.tsx
+++ b/js/app/packages/channel/Channel/Channel.tsx
@@ -120,6 +120,7 @@ export function Channel(props: ChannelProps) {
initialTargetMessageReplyId: props.targetMessageReplyId,
messageKeys: () => messageIndex.keys(),
navigation: threadListNavigation,
+ didInitialScroll: () => threadListScrollState()?.didInitialScroll ?? false,
});
const [channelInputSnapshot, setChannelInputSnapshot] =
diff --git a/js/app/packages/channel/Channel/create-target-message-controller.ts b/js/app/packages/channel/Channel/create-target-message-controller.ts
index 4f93eba73c..6ff79589d0 100644
--- a/js/app/packages/channel/Channel/create-target-message-controller.ts
+++ b/js/app/packages/channel/Channel/create-target-message-controller.ts
@@ -13,6 +13,15 @@ type CreateTargetMessageControllerOptions = {
initialTargetMessageReplyId?: string | undefined;
messageKeys: Accessor<string[]>;
navigation: Accessor<ThreadListNavigation | undefined>;
+ /**
+ * Whether the ThreadList has completed its initial scroll.
+ *
+ * The controller defers pending scroll execution until this returns `true`
+ * so that a `goToMessage` call that fires while the initial scroll is still
+ * in progress does not get overridden by the initial-scroll retry logic
+ * inside ThreadList.
+ */
+ didInitialScroll: Accessor<boolean>;
};
export type TargetMessageController = ReturnType<
@@ -83,10 +92,20 @@ export function createTargetMessageController(
options.navigation,
() => targetMessageData['pendingScrollTargetId'],
options.messageKeys,
+ options.didInitialScroll,
],
- ([navigation, pendingTargetId]) => {
+ ([navigation, pendingTargetId, , didInitialScroll]) => {
if (!navigation || !pendingTargetId) return;
if (!hasMessageLoaded(pendingTargetId)) return;
+
+ // Defer the scroll until the ThreadList has completed its initial
+ // scroll. This prevents a goToMessage call from being overridden by
+ // the initial-scroll retry logic in ThreadList's handleScrollEnd,
+ // which validates position against the *original* scroll target.
+ // The pending target stays queued; once didInitialScroll flips to
+ // true the effect re-fires and executes the scroll.
+ if (!didInitialScroll) return;
+
if (!navigation.scrollToId(pendingTargetId)) return;
const restoredDefaultPagination =
diff --git a/js/app/packages/channel/Channel/tests/create-target-message-controller.test.ts b/js/app/packages/channel/Channel/tests/create-target-message-controller.test.ts
index 7574116450..0e4974e0aa 100644
--- a/js/app/packages/channel/Channel/tests/create-target-message-controller.test.ts
+++ b/js/app/packages/channel/Channel/tests/create-target-message-controller.test.ts
@@ -21,9 +21,13 @@ function createController(
messageKeys: string[];
scrollToId: (messageId: string) => boolean;
withNavigation: boolean;
+ didInitialScroll: boolean;
}>
) {
const [messageKeys, setMessageKeys] = createSignal(input?.messageKeys ?? []);
+ const [didInitialScroll, setDidInitialScroll] = createSignal(
+ input?.didInitialScroll ?? false
+ );
const scrollToId =
input?.scrollToId ??
@@ -50,11 +54,13 @@ function createController(
markUserIntent: () => {},
}
: undefined,
+ didInitialScroll,
});
return {
controller,
setMessageKeys,
+ setDidInitialScroll,
};
}