You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by as...@apache.org on 2026/09/13 14:12:19 UTC
(maka) 01/02: fix(ui): publish virtual history during active scrolling
This is an automated email from the ASF dual-hosted git repository.
Astro-Han pushed a commit to branch fix/transcript-viewport-mounting
in repository https://gitbox.apache.org/repos/asf/maka.git
commit d79e310d592402b2859227bb1ff3cbcd828ea543
Author: AstroHan <le...@outlook.com>
AuthorDate: Sun Sep 13 22:11:10 2026 +0800
fix(ui): publish virtual history during active scrolling
---
.../session-workspace-action-identity.test.ts | 7 +-
.../main/__tests__/workhub-send-visibility.test.ts | 3 +-
.../__tests__/transcript-scroll-authority.test.ts | 95 +++++-----------------
packages/ui/src/__tests__/use-chat-scroll.test.tsx | 25 +++---
packages/ui/src/transcript-scroll-authority.tsx | 31 +------
packages/ui/src/transcript-viewport-navigation.ts | 11 +--
scripts/perf/scroll-window.mjs | 12 ++-
7 files changed, 56 insertions(+), 128 deletions(-)
diff --git a/apps/desktop/src/main/__tests__/session-workspace-action-identity.test.ts b/apps/desktop/src/main/__tests__/session-workspace-action-identity.test.ts
index 65aa195944..d67684bf5f 100644
--- a/apps/desktop/src/main/__tests__/session-workspace-action-identity.test.ts
+++ b/apps/desktop/src/main/__tests__/session-workspace-action-identity.test.ts
@@ -137,8 +137,8 @@ describe('session workspace action identity', () => {
act(() => workspace.setActiveId(sessionA));
assert.deepEqual(workspace.retiredSessionIds([{ id: sessionB }]), [sessionA]);
- // The real publication scheduler may hold a ready source while the reader
- // is interacting. A retired queued source may not replace the displayed
+ // Publication is scheduled outside the current React lifecycle.
+ // A retired queued source may not replace the displayed
// Session or publish its reader.
act(() => workspace.setActiveId(sessionC));
for (const batch of encodeDesktopTranscriptSnapshot({
@@ -148,8 +148,7 @@ describe('session workspace action identity', () => {
let blocked = true;
let idle!: () => void;
const detach = workspace.sessionUiController.transcriptViewportNavigation.attachCommitScheduler(sessionC, {
- commitIfIdle: (commit) => { if (blocked) return false; commit(); return true; },
- subscribeToIdle: (listener) => { idle = listener; return () => {}; },
+ commitRange: (commit) => { if (blocked) idle = commit; else commit(); },
});
let publications = 0;
await act(async () => workspace.publishTranscript(
diff --git a/apps/desktop/src/main/__tests__/workhub-send-visibility.test.ts b/apps/desktop/src/main/__tests__/workhub-send-visibility.test.ts
index 689312c150..66151ae0fe 100644
--- a/apps/desktop/src/main/__tests__/workhub-send-visibility.test.ts
+++ b/apps/desktop/src/main/__tests__/workhub-send-visibility.test.ts
@@ -253,8 +253,7 @@ test('WorkHub holds transcript and live handoff together until publication is ad
let held = true;
let idle!: () => void;
const detach = h.controller.viewportNavigation.attachCommitScheduler(h.sessionId, {
- commitIfIdle(commit) { if (held) return false; commit(); return true; },
- subscribeToIdle(listener) { idle = listener; return () => {}; },
+ commitRange(commit) { if (held) idle = commit; else commit(); },
});
const messages: StoredMessage[] = [
{ type: 'user', id: 'user', turnId, text: 'held prompt', ts: 1 },
diff --git a/packages/ui/src/__tests__/transcript-scroll-authority.test.ts b/packages/ui/src/__tests__/transcript-scroll-authority.test.ts
index 988c3961eb..cd59fe1d11 100644
--- a/packages/ui/src/__tests__/transcript-scroll-authority.test.ts
+++ b/packages/ui/src/__tests__/transcript-scroll-authority.test.ts
@@ -186,70 +186,38 @@ test('Ctrl and Meta wheel zoom preserve following without requesting history', (
});
});
-test('touch publication waits for the last contact to end or cancel', () => {
+test('available rows publish during wheel, touch and scrollbar input without ending the gesture', () => {
withObservers(() => {
- for (const end of ['touchend', 'touchcancel'] as const) {
+ for (const input of ['wheel', 'touch', 'scrollbar'] as const) {
const root = fakeRoot();
const authority = createTranscriptScrollAuthority();
const detach = authority.attach(root as unknown as HTMLElement);
- const publication = createTranscriptViewportNavigation();
- publication.attachCommitScheduler('session', authority);
let commits = 0;
- root.touch('touchstart', 1);
- root.touch('touchstart', 2);
- publication.commitRange('session', () => commits++);
- assert.equal(commits, 0);
- root.touch(end, 1);
- assert.equal(commits, 0, 'remaining contact still holds publication');
- root.touch(end, 0);
- assert.equal(commits, 1, 'last contact releases publication');
+ if (input === 'wheel') root.input(-100);
+ else if (input === 'touch') root.touch('touchstart', 2);
+ else root.grabScrollbar();
+ assert.equal(authority.isInputActive(), true);
+ authority.commitRange(() => commits++);
+ assert.equal(commits, 1, `${input} must not starve visible history`);
+ assert.equal(authority.isInputActive(), true, 'publication does not retire native input');
detach();
}
});
});
-test('a held scrollbar coalesces range publication until release, including a stationary hold', () => {
- withObservers((_resize, frame) => {
- const root = fakeRoot();
- const authority = createTranscriptScrollAuthority();
- authority.attach(root as unknown as HTMLElement);
- const publication = createTranscriptViewportNavigation();
- publication.attachCommitScheduler('session', authority);
- const commits: number[] = [];
- root.grabScrollbar();
- root.scrollTop -= 100;
- root.emitScroll();
- publication.commitRange('session', () => commits.push(1));
- publication.commitRange('session', () => commits.push(2));
- root.end(); frame(); frame();
- assert.deepEqual(commits, []);
- root.ownerDocument.dispatchEvent(new Event('pointerup'));
- frame(); frame();
- assert.deepEqual(commits, [2]);
- });
-});
-
-test('an edge wheel without scrollend publishes after input settles', () => {
- withObservers((_resize, frame) => {
- const root = fakeRoot();
- const authority = createTranscriptScrollAuthority();
- const detach = authority.attach(root as unknown as HTMLElement);
- const publication = createTranscriptViewportNavigation();
- const detachPublication = publication.attachCommitScheduler('session', authority);
- root.scrollTop = 0;
- let commits = 0;
- const phases: string[] = [];
- authority.subscribeToReaderScroll((phase) => {
- phases.push(phase);
- if (phase === 'input') publication.commitRange('session', () => commits++);
- });
- root.input(-100);
- assert.equal(commits, 0);
- frame(); frame();
- assert.equal(commits, 1);
- assert.deepEqual(phases, ['input', 'settled']);
- detach(); detachPublication();
+test('range publication coalesces within a microtask and uses the viewport anchor owner', async () => {
+ const publication = createTranscriptViewportNavigation();
+ const commits: number[] = [];
+ let scheduled = 0;
+ publication.attachCommitScheduler('session', {
+ commitRange(commit) { scheduled++; commit(); },
});
+ publication.commitRange('session', () => commits.push(1));
+ publication.commitRange('session', () => commits.push(2));
+ assert.deepEqual(commits, []);
+ await Promise.resolve();
+ assert.deepEqual(commits, [2]);
+ assert.equal(scheduled, 1);
});
test('content that grows under a pinned transcript keeps the tail on screen', () => {
@@ -348,27 +316,6 @@ test('scrollbar defaults can land after pointerup, while an unmoved click retire
});
});
-test('navigation during a held scrollbar still publishes on release or cancellation', async () => {
- for (const event of ['pointerup', 'pointercancel']) {
- const state = withObservers(() => {
- const root = fakeRoot();
- const authority = createTranscriptScrollAuthority();
- authority.attach(root as unknown as HTMLElement);
- const publication = createTranscriptViewportNavigation();
- publication.attachCommitScheduler('session', authority);
- const commits: number[] = [];
- root.grabScrollbar();
- publication.commitRange('session', () => commits.push(1));
- authority.releasePin();
- return { root, commits };
- });
- await Promise.resolve();
- assert.deepEqual(state.commits, [], 'navigation must preserve the physical hold');
- withObservers(() => state.root.ownerDocument.dispatchEvent(new Event(event)));
- assert.deepEqual(state.commits, [1], 'release wakes the pending publication without another update');
- }
-});
-
test('explicit navigation cancels input provenance before positioning its target', () => {
withObservers(() => {
const root = fakeRoot();
diff --git a/packages/ui/src/__tests__/use-chat-scroll.test.tsx b/packages/ui/src/__tests__/use-chat-scroll.test.tsx
index d1ca5298dc..0a98cb8090 100644
--- a/packages/ui/src/__tests__/use-chat-scroll.test.tsx
+++ b/packages/ui/src/__tests__/use-chat-scroll.test.tsx
@@ -396,7 +396,7 @@ test('an older request at offset zero does not move the reader', async () => {
assert.equal(transcript.scrollTop, 0, 'publication owns anchoring; input must not nudge the reader');
});
-test('idle range admission commits the React DOM before a subsequent input can begin', async () => {
+test('range admission commits the React DOM even if native input starts before publication', async () => {
const navigation = createTranscriptViewportNavigation();
const { document, window } = parseHTML('<main id="mount"></main><section id="scroller"></section>');
const { frames } = installScrollTestEnvironment(document, window);
@@ -419,7 +419,7 @@ test('idle range admission commits the React DOM before a subsequent input can b
navigation.commitRange('admission', () => publish('new'));
await Promise.resolve();
assert.equal(document.querySelector('#mount')!.textContent, 'new',
- 'an admitted update must not remain in React scheduling after its idle check');
+ 'an admitted update must not remain in React scheduling after publication');
});
await act(async () => {
navigation.commitRange('admission', () => publish('held'));
@@ -429,8 +429,8 @@ test('idle range admission commits the React DOM before a subsequent input can b
});
transcript.scroller.dispatchEvent(down);
await Promise.resolve();
- assert.equal(document.querySelector('#mount')!.textContent, 'new',
- 'input that starts before admission must hold the queued update');
+ assert.equal(document.querySelector('#mount')!.textContent, 'held',
+ 'available rows must reach React while native input remains held');
});
await act(() => document.dispatchEvent(new window.Event('pointerup')));
await act(() => {
@@ -461,9 +461,10 @@ test('a source publication survives viewport unmount without another source upda
mountedRoot = createRoot(document.querySelector('#mount')!);
await act(() => mountedRoot?.render(<TranscriptScrollAuthorityProvider><Harness /></TranscriptScrollAuthorityProvider>));
await act(() => wheel(transcript.scroller, -100));
- await act(() => navigation.commitRange('session', () => publish('latest')));
- assert.equal(document.querySelector('#mount')!.textContent, 'old');
- await act(() => show(false));
+ await act(() => {
+ navigation.commitRange('session', () => publish('latest'));
+ show(false);
+ });
assert.equal(document.querySelector('#mount')!.textContent, 'latest');
await act(() => show(true));
assert.equal(document.querySelector('#mount')!.textContent, 'latest');
@@ -508,7 +509,7 @@ for (const hasOlder of [false, true]) {
});
}
}));
- assert.equal(publications, 0, 'input holds publication, including an accepted history request');
+ assert.equal(publications, 1, 'input must not starve an accepted history request');
await frame(); await frame();
assert.equal(requests, hasOlder ? 1 : 0);
assert.equal(publications, 1);
@@ -522,7 +523,7 @@ for (const hasOlder of [false, true]) {
});
}
-test('a held fill publishes before trimming or chaining from the new geometry', async () => {
+test('a fill publishes during input while eviction still waits for the reader to settle', async () => {
const navigation = createTranscriptViewportNavigation();
const { document, window } = parseHTML('<main id="mount"></main><section id="scroller"></section>');
const { frames } = installScrollTestEnvironment(document, window);
@@ -578,9 +579,9 @@ test('a held fill publishes before trimming or chaining from the new geometry',
});
assert.equal(requests, 1);
await act(() => finishRead());
- assert.equal(publications, 0);
- assert.deepEqual(retained, [], 'published IDs cannot trim source while its new page is held');
- assert.equal(requests, 1, 'a held response must not chain reads using stale geometry');
+ assert.equal(publications, 1);
+ assert.deepEqual(retained, [], 'active input still prevents eviction');
+ assert.equal(requests, 1, 'the fill does not eagerly chain while input is active');
await act(() => document.dispatchEvent(new window.Event('pointerup')));
await frame(); await frame();
assert.equal(publications, 1);
diff --git a/packages/ui/src/transcript-scroll-authority.tsx b/packages/ui/src/transcript-scroll-authority.tsx
index ea214de8df..d54bb11f8e 100644
--- a/packages/ui/src/transcript-scroll-authority.tsx
+++ b/packages/ui/src/transcript-scroll-authority.tsx
@@ -61,11 +61,10 @@ export interface TranscriptScrollSnapshot {
}
export interface TranscriptScrollAuthority {
- /** Whether native input still holds the published geometry. */
+ /** Whether native input is still active; window eviction waits for it. */
isInputActive(): boolean;
- /** Synchronously publish and preserve geometry if native input permits it. */
- commitIfIdle(commit: () => void): boolean;
- subscribeToIdle(listener: () => void): () => void;
+ /** Publish available rows and preserve the current reading anchor. */
+ commitRange(commit: () => void): void;
/** Take the scroller. Returns the detach for the effect that called it. */
attach(root: HTMLElement | null): () => void;
/** One-shot: put the tail back under the reader and follow it again. */
@@ -115,7 +114,6 @@ export function createTranscriptScrollAuthority(): TranscriptScrollAuthority {
// Geometry belongs to a known input operation, never the other way around.
// scrollend also covers smooth keyboard scrolling and touchpad inertia.
let gesture: { top: number; direction?: 'up' | 'down' } | undefined;
- const idleListeners = new Set<() => void>();
let pointer: number | undefined;
let touchHeld = false;
const isInputActive = (): boolean => gesture !== undefined || pointer !== undefined || touchHeld;
@@ -140,10 +138,6 @@ export function createTranscriptScrollAuthority(): TranscriptScrollAuthority {
target.style.overflowAnchor = pinned ? 'none' : 'auto';
}
};
- const notifyIdle = (): void => {
- if (isInputActive()) return;
- for (const listener of [...idleListeners]) listener();
- };
let readingTurnId: string | undefined;
let snapshot: TranscriptScrollSnapshot = { pinned, awayFromTail, readingTurnId };
const listeners = new Set<() => void>();
@@ -183,15 +177,7 @@ export function createTranscriptScrollAuthority(): TranscriptScrollAuthority {
return {
isInputActive,
- commitIfIdle(commit) {
- if (isInputActive()) return false;
- commitRange(commit);
- return true;
- },
- subscribeToIdle(listener) {
- idleListeners.add(listener);
- return () => { idleListeners.delete(listener); };
- },
+ commitRange,
attach(next) {
root = next;
const target = root;
@@ -251,7 +237,6 @@ export function createTranscriptScrollAuthority(): TranscriptScrollAuthority {
requestAnimationFrame(() => {
if (gesture !== pending || pending.direction !== undefined) return;
gesture = undefined;
- notifyIdle();
if (pinned) writeToTail();
});
};
@@ -300,9 +285,6 @@ export function createTranscriptScrollAuthority(): TranscriptScrollAuthority {
publish();
};
const onScrollEnd = (): void => {
- // An explicit navigation may already have retired the gesture while
- // a pointer or touch was held. Release still has to wake publication.
- notifyIdle();
const ended = gesture;
if (!ended) return;
const top = ended.top;
@@ -316,7 +298,6 @@ export function createTranscriptScrollAuthority(): TranscriptScrollAuthority {
// the pin. Settling an unmoved edge gesture must not release it too.
pinned = pinned || (ended.direction === 'down' && distanceToTail() <= PIN_THRESHOLD_PX);
gesture = undefined;
- notifyIdle();
publish();
if (pinned) writeToTail();
// An anchor navigation can supersede the last in-flight page while
@@ -393,16 +374,12 @@ export function createTranscriptScrollAuthority(): TranscriptScrollAuthority {
pointer = undefined;
touchHeld = false;
pinned = true;
- queueMicrotask(notifyIdle);
writeToTail();
publish();
},
releasePin() {
gesture = undefined;
pinned = false;
- // Commands can originate in a React effect. Publish before their next
- // positioning frame, outside React's lifecycle, if a range is pending.
- queueMicrotask(notifyIdle);
awayFromTail = distanceToTail() > BUTTON_THRESHOLD_PX;
publish();
},
diff --git a/packages/ui/src/transcript-viewport-navigation.ts b/packages/ui/src/transcript-viewport-navigation.ts
index bc731ed286..4f50860d5e 100644
--- a/packages/ui/src/transcript-viewport-navigation.ts
+++ b/packages/ui/src/transcript-viewport-navigation.ts
@@ -21,7 +21,7 @@
* Publication outlives a viewport: only the source owner can invalidate its data. */
export function createTranscriptViewportNavigation() {
const listeners = new Set<(sessionId: string) => void>();
- let viewport: { sessionId: string; commitIfIdle: (commit: () => void) => boolean } | undefined;
+ let viewport: { sessionId: string; commitRange: (commit: () => void) => void } | undefined;
let pending: { sessionId: string; commit: () => void } | undefined;
const drain = (): void => {
const update = pending;
@@ -30,20 +30,17 @@ export function createTranscriptViewportNavigation() {
pending = undefined;
update.commit();
};
- if (viewport?.sessionId === update.sessionId) viewport.commitIfIdle(commit);
+ if (viewport?.sessionId === update.sessionId) viewport.commitRange(commit);
else commit();
};
return {
attachCommitScheduler(sessionId: string, authority: {
- commitIfIdle(commit: () => void): boolean;
- subscribeToIdle(listener: () => void): () => void;
+ commitRange(commit: () => void): void;
}): () => void {
- const attached = { sessionId, commitIfIdle: authority.commitIfIdle };
+ const attached = { sessionId, commitRange: authority.commitRange };
viewport = attached;
- const unsubscribe = authority.subscribeToIdle(drain);
queueMicrotask(drain);
return () => {
- unsubscribe();
if (viewport !== attached) return;
viewport = undefined;
// React cleanup may be running. Publish after it, without depending
diff --git a/scripts/perf/scroll-window.mjs b/scripts/perf/scroll-window.mjs
index 3954a6861d..86f0f7abd7 100644
--- a/scripts/perf/scroll-window.mjs
+++ b/scripts/perf/scroll-window.mjs
@@ -86,7 +86,7 @@ try {
top: root.scrollTop,
height: root.scrollHeight,
viewport: root.clientHeight,
- count: turns.length,
+ count: root.querySelectorAll('.maka-turn[data-turn-id]').length,
first: turns[0]?.dataset.turnId,
last: turns.at(-1)?.dataset.turnId,
phase: probe.phase,
@@ -105,6 +105,8 @@ try {
for (const [direction, delta] of [
['up', -450],
['down', 450],
+ ['up-repeat', -450],
+ ['down-repeat', 450],
]) {
for (let burst = 0; burst < 12; burst++) {
await page.evaluate((phase) => {
@@ -120,7 +122,7 @@ try {
await page.waitForTimeout(350);
const reached = await page.evaluate((direction) => {
const root = document.querySelector('[data-chat-scroll-container]');
- return direction === 'up'
+ return direction.startsWith('up')
? root.scrollTop <= 1
: root.scrollHeight - root.scrollTop - root.clientHeight <= 1;
}, direction);
@@ -147,10 +149,14 @@ try {
const delta = frame.height - data.frames[i].height;
return delta < -1 ? [{ ...frame, delta }] : [];
});
+ const blankFrames = data.frames.filter((frame) => frame.count === 0);
+ const revisitShrink = shrink.filter((frame) => frame.phase.startsWith('up-repeat'));
const row = {
scene,
trial,
shrinkCount: shrink.length,
+ blankFrames: blankFrames.length,
+ revisitShrinkCount: revisitShrink.length,
shrinkPx: -shrink.reduce((sum, frame) => sum + frame.delta, 0),
maxLongTaskMs: Math.max(0, ...data.tasks.map((task) => task.duration)),
longTaskMs: data.tasks.reduce((sum, task) => sum + task.duration, 0),
@@ -167,6 +173,8 @@ try {
);
await page.screenshot({ path: path.join(outputDir, `scroll-window-${scene}-${trial}.png`) });
console.log(JSON.stringify(row));
+ assert.equal(blankFrames.length, 0, 'native traversal must not expose an empty transcript');
+ assert.equal(revisitShrink.length, 0, 'revisiting measured history must preserve its extent');
await page.close();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org