Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions e2e/web/tests/issue.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,31 @@ test('alt+i lists the attachments with who added them, and it stays', async ({ p
await expect(files.locator('.thumb', { hasText: 'shot.png' })).toBeVisible();
});

// Pictures load after the comments are shown and make them taller: the end stays the end.
test('the comments stay at the latest while their pictures load', async ({ page, app }) => {
const svg = '<svg xmlns="http://www.w3.org/2000/svg" width="600" height="600"><rect width="600" height="600" fill="teal"/></svg>';
await page.route('**/api/attachments/slow-*', async route => {
await new Promise(r => setTimeout(r, 800)); // past the frames it takes to size the comments
await route.fulfill({ contentType: 'image/svg+xml', body: svg });
});
for (const n of [1, 2, 3]) {
const res = await page.request.post(app.url + '/api/issues/DEMO-4/comments', { data: { Markdown: `Shot ${n}\n\n![shot](attachment:slow-${n})` } });
expect(res.ok()).toBeTruthy();
}
await page.reload();
const p = panel(page);
await expect(p.locator('.iss-key')).toHaveText('DEMO-4');
await p.locator('.tab', { hasText: 'Comments' }).click();
const last = p.locator('.cm img.md-img').last();
await expect.poll(() => last.evaluate(n => n.complete && n.naturalHeight)).toBeGreaterThan(0);
const fromEnd = () => p.locator('.iss-scroll').evaluate(n => n.scrollHeight - n.scrollTop - n.clientHeight);
await expect.poll(fromEnd).toBeLessThan(2);
// scrolling yourself lets go of it
await p.locator('.iss-scroll').hover();
await page.mouse.wheel(0, -400);
await expect.poll(fromEnd).toBeGreaterThan(100);
});

// laneway-server's change stream (the demo has none: this stands in for it): someone else's comment
// shows in the open issue without a reload.
test.describe('on laneway-server', () => {
Expand Down
27 changes: 15 additions & 12 deletions internal/web/static/js/views/issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,15 @@ export function mountIssue(el, key, { app, full, card }) {
s ? h('span.it-st.st-' + s, { title: T('agent %s', LABEL[s] || s) }, icon(ICON[s] || ICON.unknown)) : null, label);
}));
}
// hold keeps a place in the comments (the end, a linked comment) while they still change height: as
// content-visibility sizes the ones scrolled past and as their images load. Until you scroll yourself.
let held = null;
const release = () => { held = null; };
const sized = new ResizeObserver(() => { if (held && st.tab === 'comments') held(); else release(); });
sized.observe(box.list);
for (const ev of ['wheel', 'touchmove', 'pointerdown']) root.addEventListener(ev, release, { capture: true, passive: true });
window.addEventListener('keydown', release, true); // on window: before the key itself opens the comments and holds
function hold(place) { held = place; place(); }
function setTab(t) {
const was = st.tab;
st.tab = t;
Expand All @@ -212,10 +221,7 @@ export function mountIssue(el, key, { app, full, card }) {
if (t === 'history') loadHistory();
if (t === 'comments' && st.focusId == null) focusComment(null);
if (t === 'comments' && was !== 'comments' && !newest() && !wantComment) { // oldest first: the latest is at the end
// Again each frame while content-visibility sizes the comments it scrolls past.
let h = -1, n = 0;
const end = () => { if (st.tab !== 'comments' || (scroll.scrollHeight === h && n > 1) || ++n > 20) return; h = scroll.scrollHeight; scroll.scrollTop = h; requestAnimationFrame(end); };
end();
hold(() => { scroll.scrollTop = scroll.scrollHeight; });
}
}
// The Terminal tab: shown (4, a click) or typing (ctrl+\, enter); 4 on it steps through several agents.
Expand Down Expand Up @@ -632,13 +638,10 @@ export function mountIssue(el, key, { app, full, card }) {
setTab('comments');
wantComment = null;
focusComment(id, false);
// Again each frame while content-visibility sizes the comments it scrolls past.
let n = 0;
const center = () => {
const node = st.tab === 'comments' && st.focusId === id && ++n <= 20 && box.list.querySelector('[data-id="' + CSS.escape(id) + '"]');
if (node) { node.scrollIntoView({ block: 'center' }); requestAnimationFrame(center); }
};
center();
hold(() => {
const node = st.focusId === id && box.list.querySelector('[data-id="' + CSS.escape(id) + '"]');
if (node) node.scrollIntoView({ block: 'center' });
});
}
const commentEls = () => [...box.list.children].filter(n => n.dataset.id && !n.dataset.id.startsWith('tmp-'));
function focusComment(id, scrollTo = true) {
Expand Down Expand Up @@ -983,7 +986,7 @@ export function mountIssue(el, key, { app, full, card }) {
if (startTerm) openTerm(true);

return () => {
dead = true; scope.dispose(); offChanged(); offSite(); clearTimeout(siteTimer); offFocus(); offTimer.forEach(f => f());
dead = true; sized.disconnect(); window.removeEventListener('keydown', release, true); scope.dispose(); offChanged(); offSite(); clearTimeout(siteTimer); offFocus(); offTimer.forEach(f => f());
term.dispose(); el.classList.remove('term-on');
for (const e of editors) e.dispose();
if (offNotes) offNotes();
Expand Down
Loading