TypeScript
fix(mobile): opening a pull request no longer crashes with "Maximum update depth exceeded" (#22600)
tatsuaki watanabed0c5d7c4ed90
diff --git a/apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx b/apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsxindex 10cb2d7a372..20c85f71893 100644--- a/apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx+++ b/apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx@@ -299,6 +299,18 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestPconst [headerHeight, setHeaderHeight] = useState(0);const [viewportHeight, setViewportHeight] = useState(0);const scrollViews = useRef<Partial<Record<typeof section, LegendListRef | null>>>({});+ // AnimatedLegendList re-attaches its handle and sets state whenever its ref changes,+ // so an inline ref in the tab map loops the screen into "Maximum update depth exceeded".+ const [listRefs] = useState(() => {+ const listRef = (tab: typeof section) => (list: LegendListRef | null) => {+ scrollViews.current[tab] = list;+ };+ return {+ overview: listRef("overview"),+ guide: listRef("guide"),+ activity: listRef("activity"),+ };+ });const selectSection = (next: typeof section) => {if (next === section) return;scrollOffsets.current[section] = currentScrollOffset.current;@@ -545,9 +557,7 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestPimportantForAccessibility={section === tab ? "auto" : "no-hide-descendants"}><AnimatedLegendList- ref={(list) => {- scrollViews.current[tab] = list;- }}+ ref={listRefs[tab]}initialScrollOffset={-insets.top}onScroll={(event) => {const offset = event.nativeEvent.contentOffset.y;