File tree Expand file tree Collapse file tree 4 files changed +21
-10
lines changed Expand file tree Collapse file tree 4 files changed +21
-10
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,9 @@ const useDetectClickOutside = (
1717) => {
1818 const ref = useRef < HTMLDivElement | null > ( null ) ;
1919 const onClickOutsideRef = useRef ( onClickOutside ) ;
20- onClickOutsideRef . current = onClickOutside ;
20+ useEffect ( ( ) => {
21+ onClickOutsideRef . current = onClickOutside ;
22+ } , [ onClickOutside ] ) ;
2123 const handleClickOutside = useCallback (
2224 ( event : MouseEvent ) => {
2325 const target =
Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ export const PopperComponent: React.FC<PopperComponentProps> = (props) => {
5050 const classes = clsx ( "react-datepicker-popper" , className ) ;
5151 popper = (
5252 < TabLoop enableTabLoop = { enableTabLoop } >
53+ { /* eslint-disable react-hooks/refs -- Floating UI values are designed to be used during render */ }
5354 < div
5455 ref = { popperProps . refs . setFloating }
5556 style = { popperProps . floatingStyles }
@@ -71,6 +72,7 @@ export const PopperComponent: React.FC<PopperComponentProps> = (props) => {
7172 />
7273 ) }
7374 </ div >
75+ { /* eslint-enable react-hooks/refs */ }
7476 </ TabLoop >
7577 ) ;
7678 }
@@ -91,6 +93,7 @@ export const PopperComponent: React.FC<PopperComponentProps> = (props) => {
9193
9294 return (
9395 < >
96+ { /* eslint-disable-next-line react-hooks/refs -- Floating UI refs are designed to be used during render */ }
9497 < div ref = { popperProps . refs . setReference } className = { wrapperClasses } >
9598 { targetComponent }
9699 </ div >
Original file line number Diff line number Diff line change @@ -8,26 +8,31 @@ import React, {
88import { createPortal } from "react-dom" ;
99
1010const ShadowRoot : FC < PropsWithChildren > = ( { children } ) => {
11+ const [ shadowRoot , setShadowRoot ] = useState < ShadowRoot | null > ( null ) ;
12+
1113 const containerRef = useRef < HTMLDivElement > ( null ) ;
12- const shadowRootRef = useRef < ShadowRoot > ( null ) ;
13- const [ isInitialized , setIsInitialized ] = useState ( false ) ;
14+ const isInitializedRef = useRef ( false ) ;
1415
1516 useLayoutEffect ( ( ) => {
17+ if ( isInitializedRef . current ) {
18+ return ;
19+ }
20+
1621 const container = containerRef . current ;
17- if ( isInitialized || ! container ) {
22+ if ( ! container ) {
1823 return ;
1924 }
2025
21- shadowRootRef . current =
26+ const root =
2227 container . shadowRoot ?? container . attachShadow ( { mode : "open" } ) ;
23- setIsInitialized ( true ) ;
24- } , [ isInitialized ] ) ;
28+ isInitializedRef . current = true ;
29+ // Use queueMicrotask to defer setState to avoid cascading renders
30+ queueMicrotask ( ( ) => setShadowRoot ( root ) ) ;
31+ } , [ ] ) ;
2532
2633 return (
2734 < div ref = { containerRef } >
28- { isInitialized &&
29- shadowRootRef . current &&
30- createPortal ( children , shadowRootRef . current ) }
35+ { shadowRoot && createPortal ( children , shadowRoot ) }
3136 </ div >
3237 ) ;
3338} ;
Original file line number Diff line number Diff line change @@ -56,6 +56,7 @@ export default function withFloating<T extends FloatingProps>(
5656 middleware : [
5757 flip ( { padding : 15 } ) ,
5858 offset ( 10 ) ,
59+ // eslint-disable-next-line react-hooks/refs -- Floating UI requires refs to be passed during render
5960 arrow ( { element : arrowRef } ) ,
6061 ...( props . popperModifiers ?? [ ] ) ,
6162 ] ,
You can’t perform that action at this time.
0 commit comments