Experiment dynamic change of parent

This might prevent double renders
This commit is contained in:
Lim Chee Aun 2024-04-15 17:06:44 +08:00
parent 57390a291b
commit 304ce5a3e8

View file

@ -11,6 +11,7 @@ import {
import { decodeBlurHash, getBlurHashAverageColor } from 'fast-blurhash'; import { decodeBlurHash, getBlurHashAverageColor } from 'fast-blurhash';
import { shallowEqual } from 'fast-equals'; import { shallowEqual } from 'fast-equals';
import prettify from 'html-prettify'; import prettify from 'html-prettify';
import { Fragment } from 'preact';
import { memo } from 'preact/compat'; import { memo } from 'preact/compat';
import { import {
useCallback, useCallback,
@ -406,38 +407,31 @@ function Status({
} }
// Check followedTags // Check followedTags
if (showFollowedTags && !!snapStates.statusFollowedTags[sKey]?.length) { const FollowedTagsParent = ({ children }) => (
return ( <div
<div data-state-post-id={sKey}
data-state-post-id={sKey} class="status-followed-tags"
class="status-followed-tags" onMouseEnter={debugHover}
onMouseEnter={debugHover} >
> <div class="status-pre-meta">
<div class="status-pre-meta"> <Icon icon="hashtag" size="l" />{' '}
<Icon icon="hashtag" size="l" />{' '} {snapStates.statusFollowedTags[sKey].slice(0, 3).map((tag) => (
{snapStates.statusFollowedTags[sKey].slice(0, 3).map((tag) => ( <Link
<Link key={tag}
key={tag} to={instance ? `/${instance}/t/${tag}` : `/t/${tag}`}
to={instance ? `/${instance}/t/${tag}` : `/t/${tag}`} class="status-followed-tag-item"
class="status-followed-tag-item" >
> {tag}
{tag} </Link>
</Link> ))}
))}
</div>
<Status
status={statusID ? null : status}
statusID={statusID ? status.id : null}
instance={instance}
size={size}
contentTextWeight={contentTextWeight}
readOnly={readOnly}
enableCommentHint
mediaFirst={mediaFirst}
/>
</div> </div>
); {children}
} </div>
);
const StatusParent =
showFollowedTags && !!snapStates.statusFollowedTags[sKey]?.length
? FollowedTagsParent
: Fragment;
const isSizeLarge = size === 'l'; const isSizeLarge = size === 'l';
@ -1383,7 +1377,7 @@ function Status({
]); ]);
return ( return (
<> <StatusParent>
{showReplyParent && !!(inReplyToId && inReplyToAccountId) && ( {showReplyParent && !!(inReplyToId && inReplyToAccountId) && (
<StatusCompact sKey={sKey} /> <StatusCompact sKey={sKey} />
)} )}
@ -2251,7 +2245,7 @@ function Status({
</Modal> </Modal>
)} )}
</article> </article>
</> </StatusParent>
); );
} }