@@ -93,18 +93,17 @@ const TooltipPortalComponent = ({
9393 // eslint-disable-next-line react-hooks/exhaustive-deps
9494 } , [ ( anchor as PortalAnchorRef ) ?. current ?? ( anchor as PositionedPortalAnchorRef ) ?. appendRef ?. current ] ) ;
9595
96+ const portalNode = useMemo ( ( ) => {
97+ return getOrCreateNode ( `echTooltipPortal${ scope } __${ chartId } ` , 'echTooltipPortal__invisible' , undefined , zIndex ) ;
98+ } , [ chartId , scope , zIndex ] ) ;
99+
96100 /**
97101 * This must not be removed from DOM throughout life of this component.
98102 * Otherwise the portal will loose reference to the correct node.
99103 */
100- const portalNodeElement = getOrCreateNode (
101- `echTooltipPortal${ scope } __${ chartId } ` ,
102- 'echTooltipPortal__invisible' ,
103- undefined ,
104- zIndex ,
105- ) ;
106-
107- const portalNode = useRef ( portalNodeElement ) ;
104+ useEffect ( ( ) => {
105+ document . body . appendChild ( portalNode ) ;
106+ } ) ;
108107
109108 /**
110109 * Popper instance used to manage position of tooltip.
@@ -126,7 +125,7 @@ const TooltipPortalComponent = ({
126125 if ( ! visible ) return ;
127126
128127 const { fallbackPlacements, placement, boundary, offset, boundaryPadding } = popperSettings ;
129- popper . current = createPopper ( anchorNode , portalNode . current , {
128+ popper . current = createPopper ( anchorNode , portalNode , {
130129 strategy : 'absolute' ,
131130 placement,
132131 modifiers : [
@@ -178,7 +177,7 @@ const TooltipPortalComponent = ({
178177
179178 useEffect ( ( ) => {
180179 setPopper ( ) ;
181- const nodeCopy = portalNode . current ;
180+ const nodeCopy = portalNode ;
182181
183182 return ( ) => {
184183 if ( nodeCopy . parentNode ) {
@@ -223,20 +222,20 @@ const TooltipPortalComponent = ({
223222
224223 useEffect ( ( ) => {
225224 if ( ! position && ! skipPositioning ) {
226- portalNode . current . classList . add ( 'echTooltipPortal__invisible' ) ;
225+ portalNode . classList . add ( 'echTooltipPortal__invisible' ) ;
227226 return ;
228227 }
229- portalNode . current . classList . remove ( 'echTooltipPortal__invisible' ) ;
230- } , [ position , skipPositioning ] ) ;
228+ portalNode . classList . remove ( 'echTooltipPortal__invisible' ) ;
229+ } , [ portalNode . classList , position , skipPositioning ] ) ;
231230
232231 useEffect ( ( ) => {
233232 if ( popper . current ) {
234233 updateAnchorDimensions ( ) ;
235234 void popper . current . update ( ) ;
236235 }
237- } , [ updateAnchorDimensions , popper ] ) ;
236+ } , [ updateAnchorDimensions ] ) ;
238237
239- return createPortal ( children , portalNode . current ) ;
238+ return createPortal ( children , portalNode , 'ech-tooltip-portal' ) ;
240239} ;
241240
242241TooltipPortalComponent . displayName = 'TooltipPortal' ;
0 commit comments