WaitUntilOnPage: Reduce debounce ms; remove unused hack

(1) Reduced the debouncing duration so that the final element can be rendered asap after visible.
  - If the user is scrolling non-stop, it would continue to debounce and the GUI ends up not showing the final element.
  - 25ms seems enough to prevent the initial false-positive that occurs in the scenario of "adjacent/upper elements resized late, so our element was briefly on screen when mounted". If not enough, we can make this a parameter.

(2) Removed `lastUpdateDate` that was a quick hack for Recommended section. We don't use it on that element anymore, so remove the hack to keep the file clean.
This commit is contained in:
infinite-persistence 2021-06-15 15:17:08 +08:00
parent df2c274216
commit 524370711c
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0

View file

@ -2,11 +2,10 @@
import React from 'react'; import React from 'react';
import debounce from 'util/debounce'; import debounce from 'util/debounce';
const DEBOUNCE_SCROLL_HANDLER_MS = 300; const DEBOUNCE_SCROLL_HANDLER_MS = 25;
type Props = { type Props = {
children: any, children: any,
lastUpdateDate?: any,
skipWait?: boolean, skipWait?: boolean,
placeholder?: any, placeholder?: any,
}; };
@ -15,10 +14,6 @@ export default function WaitUntilOnPage(props: Props) {
const ref = React.useRef(); const ref = React.useRef();
const [shouldRender, setShouldRender] = React.useState(false); const [shouldRender, setShouldRender] = React.useState(false);
React.useEffect(() => {
setShouldRender(false);
}, [props.lastUpdateDate]);
React.useEffect(() => { React.useEffect(() => {
const handleDisplayingRef = debounce((e) => { const handleDisplayingRef = debounce((e) => {
const element = ref && ref.current; const element = ref && ref.current;