mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(feed): measure expanded reply media height
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
resolveFeedVirtualizationMode,
|
||||
resolveReplyVirtualizationMode,
|
||||
} from '../pretext-height-estimates';
|
||||
import { EXPANDED_MEDIA_DATA_ATTRIBUTE } from '../measurement-attributes';
|
||||
|
||||
describe('pretext-height-estimates', () => {
|
||||
beforeEach(() => {
|
||||
@@ -81,6 +82,18 @@ describe('pretext-height-estimates', () => {
|
||||
expect(getReplyItemSizeFromElement(element, 'offsetHeight')).toBe(222);
|
||||
});
|
||||
|
||||
it('uses live DOM height when expanded media is inside an estimated item', () => {
|
||||
const element = document.createElement('div');
|
||||
const child = document.createElement('div');
|
||||
|
||||
Object.defineProperty(element, 'offsetHeight', { configurable: true, value: 421 });
|
||||
element.dataset.pretextHeight = '123';
|
||||
child.setAttribute(EXPANDED_MEDIA_DATA_ATTRIBUTE, 'true');
|
||||
element.appendChild(child);
|
||||
|
||||
expect(getReplyItemSizeFromElement(element, 'offsetHeight')).toBe(421);
|
||||
});
|
||||
|
||||
it('adds desktop board-label height for multiboard text posts without media', () => {
|
||||
const metrics = {
|
||||
abbrFontSizePx: 13,
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export const EXPANDED_MEDIA_DATA_ATTRIBUTE = 'data-expanded-media';
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { Comment } from '@bitsocial/bitsocial-react-hooks';
|
||||
import { layout, layoutNextLine, prepare, prepareWithSegments } from '@chenglou/pretext';
|
||||
import { getCommentMediaInfo, getHasThumbnail } from './media-utils';
|
||||
import { EXPANDED_MEDIA_DATA_ATTRIBUTE } from './measurement-attributes';
|
||||
import { removeMarkdown } from './post-utils';
|
||||
import { getRenderableMobileBacklinks } from './reply-backlink-utils';
|
||||
|
||||
@@ -839,6 +840,10 @@ export const getPretextItemSizeFromElement = (element: HTMLElement, field: 'offs
|
||||
return element.offsetWidth;
|
||||
}
|
||||
|
||||
if (element.dataset.expandedMedia === 'true' || element.querySelector(`[${EXPANDED_MEDIA_DATA_ATTRIBUTE}="true"]`)) {
|
||||
return element.offsetHeight;
|
||||
}
|
||||
|
||||
const ownEstimatedHeight = Number.parseFloat(element.dataset.pretextHeight || '');
|
||||
if (Number.isFinite(ownEstimatedHeight) && ownEstimatedHeight > 0) {
|
||||
return ownEstimatedHeight;
|
||||
|
||||
Reference in New Issue
Block a user