Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 历史消息定位就绪后立即显示
Dash02711645c262
diff --git a/apps/mobile/src/__tests__/messageFollowGesture.test.ts b/apps/mobile/src/__tests__/messageFollowGesture.test.tsindex acb96580e4..ffb1dbc211 100644--- a/apps/mobile/src/__tests__/messageFollowGesture.test.ts+++ b/apps/mobile/src/__tests__/messageFollowGesture.test.ts@@ -16,7 +16,7 @@ const renderer = source.statements.find((node): node is ts.FunctionDeclaration =));const callbackNames = ['markProgrammaticScroll', 'clearProgrammaticScroll', 'markMobileMvcpSettle',- 'isUserControllingScroll', 'getTailFollower', 'scrollToEndProgrammatically', 'runStickToLatestVerify',+ 'isUserControllingScroll', 'revealPositionedHistory', 'getTailFollower', 'scrollToEndProgrammatically', 'runStickToLatestVerify','scrollToOffsetProgrammatically', 'scrollToIndexProgrammatically','scrollToBottom', 'handleScroll', 'handleHistoryTouchStart', 'maybeTriggerHistoryTouch','handleHistoryTouchMove', 'handleHistoryTouchEnd', 'handleHistoryTouchCancel',@@ -52,6 +52,8 @@ function harness() {programmaticScrollInFlightRef: ref(false), programmaticAnimatedScrollInFlightRef: ref(false),programmaticScrollSettleAtRef: ref(0), mvcpSettleAtRef: ref(0),tailFollowerRef: ref(null),+ initialAnchorDoneRef: ref(true),+ initialRevealAnimationRef: ref<{ stop: () => void } | null>({ stop: vi.fn() }),historyPrependTransactionRef: ref(null), nativeScrollEventSequenceRef: ref(0),shareSelectionActiveRef: ref(false),scrollMetricsRef: ref({ contentHeight: 2000, offsetY: 1200, viewportHeight: 800 }),@@ -62,6 +64,7 @@ function harness() {});const environment = {...scrollModel, ...state, createMobileTailFollower, mobileDebugEnabled, mobileDebugLog,+ initialRevealProgress: { setValue: vi.fn() }, setListRevealed: vi.fn(),listRef: ref({scrollToEnd: tailScroll,scrollToIndex: vi.fn(),@@ -87,6 +90,8 @@ function harness() {} });return {...callbacks, state, tailScroll, scrollEvent,+ initialRevealProgress: environment.initialRevealProgress,+ setListRevealed: environment.setListRevealed,handleScrollEndDrag: (event = scrollEvent(state.scrollMetricsRef.current.offsetY)) => (callbacks.handleScrollEndDrag(event)),@@ -117,6 +122,27 @@ describe('streaming follow yields to the reader', () => {expect(sink.mock.calls.length > 0).toBe(recording !== 'off');});+ it('reveals positioned history immediately once, cancelling the fallback before opacity changes', () => {+ const h = harness();+ const stop = h.state.initialRevealAnimationRef.current!.stop;+ h.scrollToEndProgrammatically(false);+ vi.advanceTimersByTime(64);+ expect(stop).toHaveBeenCalledTimes(1);+ expect(h.initialRevealProgress.setValue).toHaveBeenCalledExactlyOnceWith(1);+ expect(h.setListRevealed).toHaveBeenCalledExactlyOnceWith(true);+ expect(vi.mocked(stop).mock.invocationCallOrder[0]).toBeLessThan(h.initialRevealProgress.setValue.mock.invocationCallOrder[0]);+ h.handleContentSize(400, 2500);+ vi.advanceTimersByTime(300);+ expect(h.setListRevealed).toHaveBeenCalledTimes(1);+ });++ it('does not reveal a not-yet-started initial history from unrelated layout callbacks', () => {+ const h = harness();+ h.state.initialAnchorDoneRef.current = false;+ h.runStickToLatestVerify();+ vi.advanceTimersByTime(300);+ expect(h.initialRevealProgress.setValue).not.toHaveBeenCalled();+ });it.each([1196, 1180].flatMap((offset) => ['missing', 'before-verify', 'after-verify'].map((end) => ({ offset, end }))))('releases a cancelled drag at $offset with end event $end', ({ offset, end }) => {const h = harness();diff --git a/apps/mobile/src/__tests__/messageListVirtualization.test.ts b/apps/mobile/src/__tests__/messageListVirtualization.test.tsindex 585e5e3a83..002812488b 100644--- a/apps/mobile/src/__tests__/messageListVirtualization.test.ts+++ b/apps/mobile/src/__tests__/messageListVirtualization.test.ts@@ -245,15 +245,18 @@ describe('mobile message list container', () => {expect(source).toContain('const [listRevealed, setListRevealed] = useState(false);');expect(source).toContain('setListRevealed(true);');expect(source).toContain('const initialRevealProgress = useMemo(');- expect(source).toContain('const initialRevealOpacity = useMemo(');+ expect(source).toContain('const initialRevealOpacity = initialRevealProgress;');expect(source).toContain('<Animated.View style={[styles.messageList, { opacity: initialRevealOpacity }]}>');- expect(source).toContain('MOBILE_INITIAL_ANCHOR_SETTLE_MS');- expect(source).toContain('MOBILE_INITIAL_REVEAL_MAX_MS');+ expect(source).toContain('const MOBILE_INITIAL_REVEAL_MAX_MS = 300;');+ expect(source).not.toContain('MOBILE_INITIAL_REVEAL_FADE_MS');+ expect(source).toContain('onSettled: revealPositionedHistory');+ expect(source).toContain('tailFollowerRef.current = null;');const initialAnchorEffectStart = source.indexOf('// 首次落底:完整历史已经在列表里');const initialAnchorEffectEnd = source.indexOf('// 会话切换(scrollResetKey)', initialAnchorEffectStart);const initialAnchorEffectSource = source.slice(initialAnchorEffectStart, initialAnchorEffectEnd);expect(initialAnchorEffectSource).toContain('Animated.timing(initialRevealProgress, {');expect(initialAnchorEffectSource).toContain('useNativeDriver: true');+ expect(initialAnchorEffectSource).toContain('easing: Easing.step1');expect(initialAnchorEffectSource).not.toContain('const verify =');expect(initialAnchorEffectSource).not.toContain('setTimeout(');expect(initialAnchorEffectSource).toContain('scrollToEndProgrammatically(false);');diff --git a/apps/mobile/src/__tests__/messageTailFollower.test.ts b/apps/mobile/src/__tests__/messageTailFollower.test.tsindex 4369f6bf92..2530d7665c 100644--- a/apps/mobile/src/__tests__/messageTailFollower.test.ts+++ b/apps/mobile/src/__tests__/messageTailFollower.test.ts@@ -16,10 +16,11 @@ function harness() {});const correctOffset = vi.fn((offset: number) => { snapshot.metrics.offsetY = offset; });const onMeasurementOscillation = vi.fn();+ const onSettled = vi.fn();const follower = createMobileTailFollower({- read: () => snapshot, seekEnd, correctOffset, onMeasurementOscillation,+ read: () => snapshot, seekEnd, correctOffset, onMeasurementOscillation, onSettled,});- return { snapshot, seekEnd, correctOffset, onMeasurementOscillation, follower };+ return { snapshot, seekEnd, correctOffset, onMeasurementOscillation, onSettled, follower };}function deferredSeek() {@@ -56,6 +57,42 @@ describe('one mobile tail follower', () => {expect(h.seekEnd).toHaveBeenCalledTimes(1);});+ it('reports readiness before the fallback deadline once native layout and position agree', () => {+ const h = harness();+ h.snapshot.layoutSettleAt = Date.now() + 120;+ h.follower.requestEnd(false);+ vi.advanceTimersByTime(100);+ expect(h.onSettled).not.toHaveBeenCalled();+ vi.advanceTimersByTime(60);+ expect(h.onSettled).toHaveBeenCalledTimes(1);+ expect(h.correctOffset).not.toHaveBeenCalled();+ });++ it('does not confuse seek completion or exhausted retries with verified positioning', async () => {+ const h = harness();+ const seek = deferredSeek();+ h.seekEnd.mockReturnValue(seek.promise);+ h.snapshot.metrics.offsetY = 0;+ h.correctOffset.mockImplementation(() => {});+ h.follower.requestEnd(false);+ await vi.advanceTimersByTimeAsync(400);+ expect(h.onSettled).not.toHaveBeenCalled();+ seek.resolve();+ await vi.advanceTimersByTimeAsync(2000);+ expect(h.onSettled).not.toHaveBeenCalled();+ expect(h.correctOffset).toHaveBeenCalledTimes(MOBILE_ANCHOR_VERIFY_MAX_ATTEMPTS);+ });++ it.each(['missing metrics', 'gesture', 'reset'])('does not reveal on %s', (reason) => {+ const h = harness();+ if (reason === 'missing metrics') h.snapshot.metrics.viewportHeight = 0;+ h.follower.requestEnd(false);+ if (reason === 'gesture') h.snapshot.userControllingScroll = true;+ if (reason === 'reset') h.follower.reset();+ vi.advanceTimersByTime(2000);+ expect(h.onSettled).not.toHaveBeenCalled();+ });+it('allows a queued last-index seek to discover the tail before correcting native geometry', async () => {const h = harness();const seek = deferredSeek();diff --git a/apps/mobile/src/session/MessageRenderer.tsx b/apps/mobile/src/session/MessageRenderer.tsxindex 05b822bd51..452617d24d 100644--- a/apps/mobile/src/session/MessageRenderer.tsx+++ b/apps/mobile/src/session/MessageRenderer.tsx@@ -391,11 +391,7 @@ const STICKY_SHARE_CHECK_THROTTLE_MS = 150;const SCREENSHOT_SHARE_VISIBLE_PERCENT_THRESHOLD = 10;// LegendList 变高 item 的初始估高(仅影响首帧布局定位,LegendList 挂载后按实测尺寸修正)。/** Bound the hidden initial correction so live measurement churn cannot blank the list for seconds. */-const MOBILE_INITIAL_ANCHOR_SETTLE_MS = 300;-/** Fade in on the UI thread after the hidden correction window; JS may be busy mounting cells. */-const MOBILE_INITIAL_REVEAL_FADE_MS = 100;-const MOBILE_INITIAL_REVEAL_MAX_MS = MOBILE_INITIAL_ANCHOR_SETTLE_MS- + MOBILE_INITIAL_REVEAL_FADE_MS;+const MOBILE_INITIAL_REVEAL_MAX_MS = 300;/** Maximum time a native imperative scroll may be reported as in-flight. */const MOBILE_PROGRAMMATIC_SCROLL_SETTLE_MS = 1000;/** Animated jump-to-latest commands get a little more time to settle. */@@ -822,8 +818,8 @@ export function MessageRenderer({viewportHeight: 0,});const tailFollowerRef = useRef<MobileTailFollower | null>(null);- // 完整历史从挂载起就在列表中;首次揭示交给 UI 线程,首批复杂消息占满 JS 时也不会- // 把 300ms 窗口拖成长达数秒的白屏。位置校验由 tail follower 独立管理。+ // 实际定位完成就直接显示;UI 线程只负责 300ms 兜底,不让繁忙 JS 无限延长隐藏。+ // 揭示沿用唯一 tail follower 的位置校验,不再额外等待或对旧消息做淡入。const initialAnchorDoneRef = useRef(false);const initialRevealGenerationRef = useRef(0);const initialRevealAnimationRef = useRef<Animated.CompositeAnimation | null>(null);@@ -831,14 +827,7 @@ export function MessageRenderer({() => new Animated.Value(0),[scrollResetKey],);- const initialRevealOpacity = useMemo(() => initialRevealProgress.interpolate({- inputRange: [- 0,- MOBILE_INITIAL_ANCHOR_SETTLE_MS / MOBILE_INITIAL_REVEAL_MAX_MS,- 1,- ],- outputRange: [0, 0, 1],- }), [initialRevealProgress]);+ const initialRevealOpacity = initialRevealProgress;const [listRevealed, setListRevealed] = useState(false);// Re-evaluate the near-start predicate after a prepend request releases its ref-only lock.// Without a render tick, a user who remains at the top can stall after one page because the@@ -899,6 +888,7 @@ export function MessageRenderer({nativeScrollEventSequenceRef.current = 0;scrollMetricsRef.current = { contentHeight: 0, offsetY: 0, viewportHeight: 0 };tailFollowerRef.current?.reset();+ tailFollowerRef.current = null;initialAnchorDoneRef.current = false;initialRevealGenerationRef.current += 1;initialRevealAnimationRef.current?.stop();@@ -989,6 +979,17 @@ export function MessageRenderer({|| isMomentumScrollingRef.current), []);+ const revealPositionedHistory = useCallback(() => {+ // The fallback handle also gates repeated settle notifications. Stop before+ // setting opacity so the native fallback cannot write a later hidden frame.+ const animation = initialRevealAnimationRef.current;+ if (!initialAnchorDoneRef.current || !animation) return;+ initialRevealAnimationRef.current = null;+ animation.stop();+ initialRevealProgress.setValue(1);+ setListRevealed(true);+ }, [initialRevealProgress]);+const getTailFollower = useCallback(() => {if (!tailFollowerRef.current) {tailFollowerRef.current = createMobileTailFollower({@@ -1012,10 +1013,11 @@ export function MessageRenderer({onMeasurementOscillation: () => console.warn('[message-list] contentSize follow-pin circuit tripped: oscillating item measurements suspected',),+ onSettled: revealPositionedHistory,});}return tailFollowerRef.current;- }, [isUserControllingScroll, markProgrammaticScroll]);+ }, [isUserControllingScroll, markProgrammaticScroll, revealPositionedHistory]);const scrollToEndProgrammatically = useCallback((animated: boolean,@@ -2270,9 +2272,8 @@ export function MessageRenderer({scheduleHistoryAnchorRestore,]);- // 首次落底:完整历史已经在列表里。短暂遮住命令式落底与首轮测量校正,随后由 native- // Animated 在 UI 线程按真实时间揭开;运行中消息持续 resize 或复杂 cell 占满 JS 时,- // 都不能把数据已在本地的消息区继续隐藏数秒。+ // 首次落底:完整历史已经在列表里。校验到位即显示,native Animated 只作上限兜底。+ // 没有淡入阶段;持续 resize 或复杂 cell 占满 JS 也不能无限延长隐藏。useLayoutEffect(() => {if (initialAnchorDoneRef.current) return;if (listData.length === 0) {@@ -2293,7 +2294,7 @@ export function MessageRenderer({const revealAnimation = Animated.timing(initialRevealProgress, {duration: MOBILE_INITIAL_REVEAL_MAX_MS,- easing: Easing.linear,+ easing: Easing.step1,toValue: 1,useNativeDriver: true,});diff --git a/apps/mobile/src/session/messageTailFollower.ts b/apps/mobile/src/session/messageTailFollower.tsindex 2a82a7e8a4..0e7e932f65 100644--- a/apps/mobile/src/session/messageTailFollower.ts+++ b/apps/mobile/src/session/messageTailFollower.ts@@ -24,6 +24,8 @@ export interface MobileTailFollowerAdapter {/** Correct using the same native coordinate system used to verify the result. */correctOffset: (offset: number) => void;onMeasurementOscillation?: () => void;+ /** Native geometry is verified; seeking completion alone is not readiness. */+ onSettled?: () => void;}/**@@ -120,6 +122,7 @@ export function createMobileTailFollower(adapter: MobileTailFollowerAdapter) {});if (action === 'settled' || action === 'give-up') {active = false;+ if (action === 'settled') adapter.onSettled?.();return;}if (action === 'retry') adapter.correctOffset(mobileMessageListEndOffset(current.metrics));