mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
perf(board): reduce desktop reverse-scroll jank on /all
Apply the asymmetric viewport buffer that already fixed mobile to desktop
multiboard feeds, and trim per-post mount cost so remounts during scroll-up
are cheaper:
- Desktop multiboard buffer goes from {600,600} to {1200,2400} (top-heavy),
matching the mobile pattern from 99c0bbfac so items stay mounted longer
when scrolling back up
- Cache feed post height estimate by CID in pretext-height-estimates so
remounts skip the Pretext text-measurement work
- Memoize CommentMedia and switch its expanded-media-store reads to atomic
selectors so it stops rerendering on unrelated store changes
- Memoize useCommentMediaInfo return so its reference is stable for memo
comparators downstream
- Stop useFetchGifFirstFrame from forcing an extra render on every post
mount by bailing out of equivalent setState calls
- Extract PendingModerationActions out of PostInfo so the two
usePublishCommentModeration calls only run on the post page when
mod-approval is actually pending, not on every feed item
This commit is contained in:
@@ -34,12 +34,15 @@ vi.mock('../../../lib/utils/url-utils', () => ({
|
||||
getHostname: () => testState.hostname,
|
||||
}));
|
||||
|
||||
vi.mock('../../../stores/use-expanded-media-store', () => ({
|
||||
default: () => ({
|
||||
vi.mock('../../../stores/use-expanded-media-store', () => {
|
||||
const getState = () => ({
|
||||
fitExpandedImagesToScreen: testState.fitExpandedImagesToScreen,
|
||||
unmuteExpandedVideoSound: testState.unmuteExpandedVideoSound,
|
||||
}),
|
||||
}));
|
||||
});
|
||||
return {
|
||||
default: (selector?: (s: ReturnType<typeof getState>) => unknown) => (selector ? selector(getState()) : getState()),
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock('../../../hooks/use-fetch-gif-first-frame', () => ({
|
||||
default: () => ({
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useState } from 'react';
|
||||
import React, { memo, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { CommentMediaInfo, getDisplayMediaInfoType, getHasThumbnail, getMediaDimensions } from '../../lib/utils/media-utils';
|
||||
import { getHostname } from '../../lib/utils/url-utils';
|
||||
@@ -202,7 +202,8 @@ const Media = ({ commentMediaInfo, disableToggle, isReply, setShowThumbnail }: M
|
||||
const { t } = useTranslation();
|
||||
const { thumbnail, type, url } = commentMediaInfo || {};
|
||||
const isMobile = useIsMobile();
|
||||
const { fitExpandedImagesToScreen, unmuteExpandedVideoSound } = useExpandedMediaStore();
|
||||
const fitExpandedImagesToScreen = useExpandedMediaStore((s) => s.fitExpandedImagesToScreen);
|
||||
const unmuteExpandedVideoSound = useExpandedMediaStore((s) => s.unmuteExpandedVideoSound);
|
||||
const mediaClass = `${isMobile ? styles.mediaMobile : isReply ? styles.mediaDesktopReply : styles.mediaDesktopOp} ${
|
||||
fitExpandedImagesToScreen ? styles.fitToScreen : ''
|
||||
}`;
|
||||
@@ -299,7 +300,7 @@ const Image = ({ commentMediaInfo, disableToggle = false, displayHeight, display
|
||||
const isReply = parentCid;
|
||||
const isMobile = useIsMobile();
|
||||
const [isImageExpanded, setIsImageExpanded] = useState(initialExpanded);
|
||||
const { fitExpandedImagesToScreen } = useExpandedMediaStore();
|
||||
const fitExpandedImagesToScreen = useExpandedMediaStore((s) => s.fitExpandedImagesToScreen);
|
||||
const mediaDimensions = getMediaDimensions(commentMediaInfo);
|
||||
const mediaClass = `${isMobile ? styles.mediaMobile : isReply ? styles.mediaDesktopReply : styles.mediaDesktopOp} ${
|
||||
fitExpandedImagesToScreen ? styles.fitToScreen : ''
|
||||
@@ -501,4 +502,21 @@ const CommentMedia = ({
|
||||
);
|
||||
};
|
||||
|
||||
export default CommentMedia;
|
||||
export default memo(CommentMedia, (prev, next) => {
|
||||
return (
|
||||
prev.commentMediaInfo === next.commentMediaInfo &&
|
||||
prev.deleted === next.deleted &&
|
||||
prev.disableToggle === next.disableToggle &&
|
||||
prev.isFloatingEmbed === next.isFloatingEmbed &&
|
||||
prev.isOutOfFeed === next.isOutOfFeed &&
|
||||
prev.isReply === next.isReply &&
|
||||
prev.linkHeight === next.linkHeight &&
|
||||
prev.linkWidth === next.linkWidth &&
|
||||
prev.parentCid === next.parentCid &&
|
||||
prev.purged === next.purged &&
|
||||
prev.removed === next.removed &&
|
||||
prev.showThumbnail === next.showThumbnail &&
|
||||
prev.setShowThumbnail === next.setShowThumbnail &&
|
||||
prev.spoiler === next.spoiler
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user