Protections on viewStory after we've unmounted
This commit is contained in:
parent
e2b217edbc
commit
4d67c6b056
|
@ -2,7 +2,13 @@
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
import FocusTrap from 'focus-trap-react';
|
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 classNames from 'classnames';
|
||||||
import { useSpring, animated, to } from '@react-spring/web';
|
import { useSpring, animated, to } from '@react-spring/web';
|
||||||
import type { BodyRangeType, LocalizerType } from '../types/Util';
|
import type { BodyRangeType, LocalizerType } from '../types/Util';
|
||||||
|
@ -197,6 +203,13 @@ export const StoryViewer = ({
|
||||||
};
|
};
|
||||||
}, [attachment]);
|
}, [attachment]);
|
||||||
|
|
||||||
|
const unmountRef = useRef<boolean>(false);
|
||||||
|
useEffect(() => {
|
||||||
|
return () => {
|
||||||
|
unmountRef.current = true;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
const [styles, spring] = useSpring(
|
const [styles, spring] = useSpring(
|
||||||
() => ({
|
() => ({
|
||||||
from: { width: 0 },
|
from: { width: 0 },
|
||||||
|
@ -204,6 +217,13 @@ export const StoryViewer = ({
|
||||||
loop: true,
|
loop: true,
|
||||||
onRest: {
|
onRest: {
|
||||||
width: ({ value }) => {
|
width: ({ value }) => {
|
||||||
|
if (unmountRef.current) {
|
||||||
|
log.info(
|
||||||
|
'stories.StoryViewer.spring.onRest: called after component unmounted'
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (value === 100) {
|
if (value === 100) {
|
||||||
viewStory(
|
viewStory(
|
||||||
story.messageId,
|
story.messageId,
|
||||||
|
|
|
@ -9293,6 +9293,13 @@
|
||||||
"reasonCategory": "usageTrusted",
|
"reasonCategory": "usageTrusted",
|
||||||
"updated": "2022-04-29T23:54:21.656Z"
|
"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",
|
"rule": "React-useRef",
|
||||||
"path": "ts/components/StoryViewsNRepliesModal.tsx",
|
"path": "ts/components/StoryViewsNRepliesModal.tsx",
|
||||||
|
|
Loading…
Reference in New Issue