fix(post): align op permalinks to the outer thread container (#1050)

* fix(post): align op permalinks to the outer thread container

* perf(scroll-to-reply): stop interval when max attempts/duration reached
This commit is contained in:
Tommaso Casaburi
2026-03-10 18:08:20 +08:00
committed by GitHub
parent 4cb5c4a833
commit 6ed3708322
13 changed files with 382 additions and 151 deletions
+33 -1
View File
@@ -1,7 +1,7 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { copyToClipboard } from '../clipboard-utils';
import { hashStringToColor, getTextColorForBackground, removeMarkdown } from '../post-utils';
import { preloadThemeAssets } from '../preload-utils';
import { preloadReplyModal, preloadThemeAssets } from '../preload-utils';
import { computeOmittedCount, filterRepliesForDisplay, getPreviewDisplayReplies, getTotalReplyCount } from '../replies-preview-utils';
import { getQuotedCidsFromContent, mergeQuotedCids } from '../reply-quote-utils';
import { formatUserIDForDisplay, truncateWithEllipsisInMiddle } from '../string-utils';
@@ -119,6 +119,38 @@ describe('misc utils', () => {
expect(loadedSources).toEqual(['/buttons/default.png', '/buttons/hover.png', '/backgrounds/wallpaper.png']);
});
it('schedules reply modal preload with requestIdleCallback when available', () => {
const requestIdleCallback = vi.fn();
Object.defineProperty(window, 'requestIdleCallback', {
configurable: true,
value: requestIdleCallback,
});
preloadReplyModal();
expect(requestIdleCallback).toHaveBeenCalledWith(expect.any(Function), { timeout: 1500 });
});
it('falls back to setTimeout for reply modal preload when requestIdleCallback is unavailable', () => {
const originalRequestIdleCallback = window.requestIdleCallback;
// @ts-expect-error test fallback path
delete window.requestIdleCallback;
vi.useFakeTimers();
const setTimeoutSpy = vi.spyOn(window, 'setTimeout');
preloadReplyModal();
expect(setTimeoutSpy).toHaveBeenCalledWith(expect.any(Function), 500);
if (originalRequestIdleCallback) {
Object.defineProperty(window, 'requestIdleCallback', {
configurable: true,
value: originalRequestIdleCallback,
});
}
});
it('builds reply previews, omitted counts, and fallback reply totals', () => {
expect(filterRepliesForDisplay([{ cid: 'visible' }, { cid: 'deleted', deleted: true }, { cid: 'removed', deleted: false }])).toEqual([
{ cid: 'visible' },