From 2adde5eb2c41f7fdb4aa8136f8de5ffe9b720b6d Mon Sep 17 00:00:00 2001 From: Vivek Kumar <35863227+techievivek@users.noreply.github.com> Date: Tue, 27 Feb 2024 16:05:08 +0530 Subject: [PATCH] Merge pull request #37261 from dukenv0307/fix/37253-console-error-show-up Fix/37253: Console log error when opening thread (cherry picked from commit a13a69d6c17a3c38a9f974557f062fff0e6be644) --- src/components/FlatList/MVCPFlatList.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/components/FlatList/MVCPFlatList.js b/src/components/FlatList/MVCPFlatList.js index 0abb1dc4a873..7fa8b364fb0f 100644 --- a/src/components/FlatList/MVCPFlatList.js +++ b/src/components/FlatList/MVCPFlatList.js @@ -38,6 +38,7 @@ const MVCPFlatList = React.forwardRef(({maintainVisibleContentPosition, horizont const firstVisibleViewRef = React.useRef(null); const mutationObserverRef = React.useRef(null); const lastScrollOffsetRef = React.useRef(0); + const isListRenderedRef = React.useRef(false); const getScrollOffset = React.useCallback(() => { if (scrollRef.current == null) { @@ -137,6 +138,9 @@ const MVCPFlatList = React.forwardRef(({maintainVisibleContentPosition, horizont }, [adjustForMaintainVisibleContentPosition, getContentView, getScrollOffset, scrollToOffset]); React.useEffect(() => { + if (!isListRenderedRef.current) { + return; + } requestAnimationFrame(() => { prepareForMaintainVisibleContentPosition(); setupMutationObserver(); @@ -186,6 +190,10 @@ const MVCPFlatList = React.forwardRef(({maintainVisibleContentPosition, horizont onScroll={onScrollInternal} scrollEventThrottle={1} ref={onRef} + onLayout={(e) => { + isListRenderedRef.current = true; + props.onLayout?.(e); + }} /> ); });