-
Notifications
You must be signed in to change notification settings - Fork 30
fix(web): preserve virtual transcript reading and focus order #552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+121
−0
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d1f1426
fix(web): preserve virtual transcript reading and focus order
lidge-jun 39f8c61
merge: carry baseline regression repairs into DOM order layer
lidge-jun 70fc46c
merge: propagate final rendering baseline coverage into DOM layer
lidge-jun d1763be
merge: propagate rendering and refresh oracle repairs
lidge-jun c4cd273
merge: propagate real reconnect readiness fixtures
lidge-jun 5ddfc4f
Merge branch 'codex/native-activity-dev-reconcile' into codex/native-…
lidge-jun b9b764a
Merge branch 'codex/native-activity-dev-reconcile' into codex/native-…
lidge-jun 1cddbde
Merge branch 'codex/native-activity-dev-reconcile' into codex/native-…
lidge-jun 60a22a4
Merge branch 'codex/native-activity-dev-reconcile' into codex/native-…
lidge-jun 0e2a7b4
Merge codex/native-activity-dev-reconcile into codex/native-activity-…
lidge-jun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| import '../setup/isolated-home.ts'; | ||
| import test, { mock } from 'node:test'; | ||
| import assert from 'node:assert/strict'; | ||
| import { setupWebUiDom, resetWebUiDom } from './web-ui-test-dom.ts'; | ||
|
|
||
| let visible = [2, 3]; | ||
| let change: () => void = () => {}; | ||
| // Control only the measured window. The real VirtualScroll owns DOM/lifecycle. | ||
| class Geometry { | ||
| options: Record<string, unknown>; | ||
| constructor(options: Record<string, unknown>) { | ||
| this.options = options; | ||
| change = options['onChange'] as () => void; | ||
| } | ||
| _didMount() { return () => {}; } | ||
| _willUpdate() {} | ||
| getVirtualItems() { return visible.map(index => ({ index, start: index * 100, size: 100, end: (index + 1) * 100, key: index })); } | ||
| getTotalSize() { return 400; } | ||
| setOptions(options: Record<string, unknown>) { this.options = options; } | ||
| measureElement() {} | ||
| measure() {} | ||
| scrollToIndex() {} | ||
| scrollToOffset() {} | ||
| } | ||
| mock.module('@tanstack/virtual-core', { namedExports: { | ||
| Virtualizer: Geometry, elementScroll() {}, observeElementRect() {}, observeElementOffset() {}, | ||
| } }); | ||
| mock.module('../../public/js/render.js', { namedExports: { releaseMermaidNodes() {} } }); | ||
| mock.module('../../public/js/features/process-block.js', { namedExports: { releaseProcessBlockDetails() {} } }); | ||
|
|
||
| let view: import('../../public/js/virtual-scroll.ts').VirtualScroll; | ||
| test.beforeEach(async () => { | ||
| setupWebUiDom(); visible = [2, 3]; | ||
| const { VirtualScroll } = await import('../../public/js/virtual-scroll.ts'); | ||
| view = new VirtualScroll('chatMessages'); | ||
| view.setItems(Array.from({ length: 4 }, (_, index) => ({ | ||
| id: String(index), messageId: String(index), height: 100, | ||
| html: `<div class="msg" data-message-id="${index}"><button id="row-${index}" class="lazy-pending">메시지 ${index}</button></div>`, | ||
| })), { autoActivate: false }); | ||
| view.activateIfNeeded(false); | ||
| }); | ||
| test.afterEach(() => { view.clear(); resetWebUiDom(); mock.restoreAll(); }); | ||
|
|
||
| const inner = () => document.querySelector<HTMLElement>('.vs-inner')!; | ||
| const order = () => Array.from(inner().children, el => Number((el as HTMLElement).dataset['vsIdx'])); | ||
| const button = (index: number) => document.getElementById(`row-${index}`)!; | ||
|
|
||
| test('backward window orders DOM before lazy/postRender and retains focused node identity', () => { | ||
| const retained = button(2); const row = retained.parentElement; | ||
| retained.focus(); | ||
| const observations: number[][] = []; | ||
| const recycled: HTMLElement[] = []; | ||
| view.onLazyRender = () => { observations.push(order()); }; | ||
| view.onPostRender = () => { observations.push(order()); }; | ||
| view.addLifecycleHooks({ postRender: () => { observations.push(order()); }, recycle: el => { recycled.push(el); } }); | ||
| visible = [0, 1, 2, 3]; change(); | ||
| assert.deepEqual(order(), [0, 1, 2, 3]); | ||
| assert.deepEqual(observations, [[0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3]]); | ||
| assert.equal(button(2), retained); assert.equal(retained.parentElement, row); | ||
| assert.equal(document.activeElement, retained); | ||
| assert.deepEqual(recycled, []); | ||
| visible = [1, 2, 3]; change(); | ||
| assert.deepEqual(order(), [1, 2, 3]); assert.equal(document.activeElement, retained); | ||
| assert.deepEqual(recycled.map(el => el.dataset['messageId']), ['0']); | ||
| }); | ||
|
|
||
| test('outside focus is not stolen when older rows mount', () => { | ||
| const outside = document.getElementById('btnSend')!; outside.focus(); | ||
| visible = [0, 1, 2, 3]; change(); | ||
| assert.deepEqual(order(), [0, 1, 2, 3]); | ||
| assert.equal(document.activeElement, outside); | ||
| }); | ||
|
|
||
| test('an evicted focused row is never restored', () => { | ||
| const removed = button(2); removed.focus(); | ||
| const focus = mock.method(removed, 'focus'); | ||
| visible = [0, 1]; change(); | ||
| assert.deepEqual(order(), [0, 1]); assert.equal(removed.isConnected, false); | ||
| assert.notEqual(document.activeElement, removed); assert.equal(focus.mock.callCount(), 0); | ||
| }); | ||
|
|
||
| test('unchanged ordered window performs no DOM moves or focus calls', () => { | ||
| visible = [0, 1, 2, 3]; change(); | ||
| const retained = button(2); retained.focus(); | ||
| const move = mock.method(inner(), 'insertBefore'); | ||
| const focus = mock.method(retained, 'focus'); | ||
| change(); | ||
| assert.equal(move.mock.callCount(), 0); assert.equal(focus.mock.callCount(), 0); | ||
| assert.equal(document.activeElement, retained); | ||
| }); | ||
|
|
||
| test('explicitly reordered retained DOM restores lost focus without scrolling', () => { | ||
| visible = [0, 1, 2, 3]; change(); | ||
| // Boundary probe only: simulate an external DOM owner, NOT reversed geometry | ||
| // or a normal TanStack scroll window. JSDOM moves lose focused descendants. | ||
| for (const index of [0, 1, 2, 3]) inner().prepend(button(index).parentElement!); | ||
| assert.deepEqual(order(), [3, 2, 1, 0]); | ||
| const retained = button(0); retained.focus(); | ||
| const focus = mock.method(retained, 'focus'); | ||
| change(); | ||
| assert.deepEqual(order(), [0, 1, 2, 3]); assert.equal(button(0), retained); | ||
| assert.equal(document.activeElement, retained); assert.equal(focus.mock.callCount(), 1); | ||
| assert.deepEqual(focus.mock.calls[0]?.arguments, [{ preventScroll: true }]); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change adds a test file and 15 lines under
public/, but leavesstructure/str_func.mdand its count verifier untouched. The repository sync guide explicitly requires updating both whenevertests/orpublic/changes, so refresh the derived structure metadata and its verification coverage in this commit.AGENTS.md reference: structure/AGENTS.md:L7-L7
Useful? React with 👍 / 👎.