Protections on viewStory after we've unmounted

This commit is contained in:
Josh Perez 2022-07-19 16:38:32 -04:00 committed by GitHub
parent e2b217edbc
commit 4d67c6b056
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -2,7 +2,13 @@
// SPDX-License-Identifier: AGPL-3.0-only
import FocusTrap from 'focus-trap-react';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import React, {
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from 'react';
import classNames from 'classnames';
import { useSpring, animated, to } from '@react-spring/web';
import type { BodyRangeType, LocalizerType } from '../types/Util';
@ -197,6 +203,13 @@ export const StoryViewer = ({
};
}, [attachment]);
const unmountRef = useRef<boolean>(false);
useEffect(() => {
return () => {
unmountRef.current = true;
};
});
const [styles, spring] = useSpring(
() => ({
from: { width: 0 },
@ -204,6 +217,13 @@ export const StoryViewer = ({
loop: true,
onRest: {
width: ({ value }) => {
if (unmountRef.current) {
log.info(
'stories.StoryViewer.spring.onRest: called after component unmounted'
);
return;
}
if (value === 100) {
viewStory(
story.messageId,

View File

@ -9293,6 +9293,13 @@
"reasonCategory": "usageTrusted",
"updated": "2022-04-29T23:54:21.656Z"
},
{
"rule": "React-useRef",
"path": "ts/components/StoryViewer.tsx",
"line": " const unmountRef = useRef<boolean>(false);",
"reasonCategory": "usageTrusted",
"updated": "2022-07-18T23:30:04.033Z"
},
{
"rule": "React-useRef",
"path": "ts/components/StoryViewsNRepliesModal.tsx",