mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
perf(react-doctor): fix compiler-blocking patterns, raise score 72→81
Replace sync setState-in-effect with keyed remount and render-derived patterns in app, error-display, topbar-edit-modal, catalog-filters; use useCurrentTime() instead of Date.now() in hot paths; fix conditional hooks, passive scroll listeners, lodash path imports.
This commit is contained in:
@@ -22,6 +22,7 @@ import useFetchGifFirstFrame from '../../hooks/use-fetch-gif-first-frame';
|
||||
import useHide from '../../hooks/use-hide';
|
||||
import useStateString from '../../hooks/use-state-string';
|
||||
import useScrollToReply from '../../hooks/use-scroll-to-reply';
|
||||
import { useCurrentTime } from '../../hooks/use-current-time';
|
||||
import { useSubplebbitField } from '../../hooks/use-stable-subplebbit';
|
||||
import CommentContent from '../comment-content';
|
||||
import CommentMedia from '../comment-media';
|
||||
@@ -33,7 +34,8 @@ import ReplyQuotePreview from '../reply-quote-preview';
|
||||
import Tooltip from '../tooltip';
|
||||
import { PostProps } from '../../views/post/post';
|
||||
import { create } from 'zustand';
|
||||
import { capitalize, lowerCase } from 'lodash';
|
||||
import capitalize from 'lodash/capitalize';
|
||||
import lowerCase from 'lodash/lowerCase';
|
||||
import { shouldShowSnow } from '../../lib/snow';
|
||||
import useReplyModalStore from '../../stores/use-reply-modal-store';
|
||||
import { selectPostMenuProps } from '../../lib/utils/post-menu-props';
|
||||
@@ -48,6 +50,13 @@ import { REPLIES_PER_PAGE } from '../../lib/constants';
|
||||
|
||||
const { addChallenge } = useChallengesStore.getState();
|
||||
|
||||
const RepliesFooter = ({ hasMore, loadingString }: { hasMore: boolean; loadingString: string }) =>
|
||||
hasMore ? (
|
||||
<div className={styles.stateString}>
|
||||
<LoadingEllipsis string={loadingString} />
|
||||
</div>
|
||||
) : null;
|
||||
|
||||
// Store scroll position for replies virtuoso across navigations
|
||||
const lastVirtuosoStates: { [key: string]: StateSnapshot } = {};
|
||||
|
||||
@@ -102,6 +111,7 @@ const PostInfo = ({
|
||||
const isInPostPageView = isPostPageView(location.pathname, params);
|
||||
const isInModQueueView = isModQueueView(location.pathname);
|
||||
const { getAlertThresholdSeconds } = useModQueueStore();
|
||||
const currentTime = useCurrentTime();
|
||||
const account = useAccount();
|
||||
const accountAddress = account?.author?.address;
|
||||
|
||||
@@ -199,7 +209,7 @@ const PostInfo = ({
|
||||
const alreadyApproved = approved === true;
|
||||
const alreadyRejected = removed === true;
|
||||
const isAwaitingApproval = isInModQueueView && !alreadyApproved && !alreadyRejected;
|
||||
const timeWaiting = timestamp ? Date.now() / 1000 - timestamp : 0;
|
||||
const timeWaiting = timestamp ? currentTime - timestamp : 0;
|
||||
const alertThresholdSeconds = getAlertThresholdSeconds();
|
||||
const isOverThreshold = isAwaitingApproval && timeWaiting > alertThresholdSeconds;
|
||||
|
||||
@@ -762,7 +772,7 @@ const PostDesktop = ({
|
||||
}
|
||||
});
|
||||
};
|
||||
window.addEventListener('scroll', setLastVirtuosoState);
|
||||
window.addEventListener('scroll', setLastVirtuosoState, { passive: true });
|
||||
return () => window.removeEventListener('scroll', setLastVirtuosoState);
|
||||
}, [virtuosoStateKey, showAllReplies, isInPostPageView]);
|
||||
|
||||
@@ -778,13 +788,7 @@ const PostDesktop = ({
|
||||
enabled: shouldScrollToReply,
|
||||
});
|
||||
|
||||
// Footer component for Virtuoso showing loading state
|
||||
const RepliesFooter = () =>
|
||||
hasMore ? (
|
||||
<div className={styles.stateString}>
|
||||
<LoadingEllipsis string={t('loading')} />
|
||||
</div>
|
||||
) : null;
|
||||
const virtuosoFooter = useCallback(() => <RepliesFooter hasMore={hasMore} loadingString={t('loading')} />, [hasMore, t]);
|
||||
|
||||
return (
|
||||
<div className={styles.postDesktop}>
|
||||
@@ -885,7 +889,7 @@ const PostDesktop = ({
|
||||
</div>
|
||||
)}
|
||||
useWindowScroll={true}
|
||||
components={{ Footer: RepliesFooter }}
|
||||
components={{ Footer: virtuosoFooter }}
|
||||
endReached={loadMore}
|
||||
ref={virtuosoRef}
|
||||
restoreStateFrom={lastVirtuosoState}
|
||||
|
||||
@@ -12,7 +12,7 @@ import { getBoardPath } from '../../../lib/utils/route-utils';
|
||||
import { useDirectories } from '../../../hooks/use-directories';
|
||||
import { isAllView, isCatalogView, isPostPageView, isSubscriptionsView } from '../../../lib/utils/view-utils';
|
||||
import useHide from '../../../hooks/use-hide';
|
||||
import { capitalize } from 'lodash';
|
||||
import capitalize from 'lodash/capitalize';
|
||||
import { PostMenuProps } from '../../../lib/utils/post-menu-props';
|
||||
|
||||
type CopyLinkButtonProps =
|
||||
|
||||
Reference in New Issue
Block a user