55
66import { queryOptions , useSuspenseQuery } from "@tanstack/react-query" ;
77import { Navigate , createFileRoute , redirect } from "@tanstack/react-router" ;
8- import { useEffect , useMemo , useRef } from "react" ;
8+ import { useCallback , useEffect , useMemo , useRef } from "react" ;
99import { preload } from "react-dom" ;
1010import { graphql } from "../gql" ;
1111import { graphqlRequest } from "../graphql" ;
@@ -50,7 +50,7 @@ function Plan(): React.ReactElement {
5050
5151 // Query the size of the iframe content and set the height
5252 // This will only work where the iframe is served from the same origin
53- const calculateHeight = ( ) => {
53+ const calculateHeight = useCallback ( ( ) => {
5454 const iframe = ref . current ;
5555 if ( ! iframe ) {
5656 return ;
@@ -63,21 +63,21 @@ function Plan(): React.ReactElement {
6363 } else {
6464 iframe . height = "500px" ;
6565 }
66- } ;
66+ } , [ ] ) ;
6767
6868 const observer = useMemo (
6969 ( ) =>
7070 new MutationObserver ( ( _mutationsList ) => {
7171 // we calculate the height immediately when the observer is triggered
7272 calculateHeight ( ) ;
73- // then we recalculate the height after a short timeout
74- // to ensure that any layout changes have settled
73+ // then we recalculate the height after a short timeout to allow for any rendering
74+ // that doesn't trigger a mutation. e.g. an iframe
7575 setTimeout ( ( ) => {
7676 calculateHeight ( ) ;
7777 } , 1000 ) ;
7878 // n.b. we don't worry about the timeout happening after the component is unmounted
7979 } ) ,
80- [ ] ,
80+ [ calculateHeight ] ,
8181 ) ;
8282
8383 useEffect ( ( ) => {
@@ -87,7 +87,7 @@ function Plan(): React.ReactElement {
8787 }
8888 // Cleanup observer when the component unmounts
8989 return ( ) => observer . disconnect ( ) ;
90- } , [ ] ) ;
90+ } , [ observer ] ) ;
9191
9292 const attachObserver = ( iframe : HTMLIFrameElement ) => {
9393 const iframeBody = iframe . contentWindow ?. document . body ;
0 commit comments