Fix render loop in <ConversationHero>

This commit is contained in:
Evan Hahn 2021-05-05 17:35:32 -05:00 committed by GitHub
parent 8ef14e6f39
commit 7afbbb3a4c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2049 additions and 2031 deletions

View file

@ -111,7 +111,9 @@ export const ConversationHero = ({
}: Props): JSX.Element => {
const firstRenderRef = useRef(true);
const previousHeightRef = useRef<undefined | number>();
const [height, setHeight] = useState<undefined | number>();
const [
isShowingMessageRequestWarning,
setIsShowingMessageRequestWarning,
@ -130,11 +132,19 @@ export const ConversationHero = ({
}, []);
useEffect(() => {
if (!firstRenderRef.current && onHeightChange) {
onHeightChange();
// We only want to kick off a "height change" when the height goes from number to
// number. We DON'T want to do it when we measure the height for the first time, as
// this will cause a re-render loop.
const previousHeight = previousHeightRef.current;
if (previousHeight && height && previousHeight !== height) {
onHeightChange?.();
}
}, [height, onHeightChange]);
useEffect(() => {
previousHeightRef.current = height;
}, [height]);
let avatarBlur: AvatarBlur;
let avatarOnClick: undefined | (() => void);
if (

File diff suppressed because it is too large Load diff