File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
src/internal/hooks/use-intersection-observer Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,18 @@ export function useIntersectionObserver<T extends HTMLElement>({
30
30
31
31
// Create a new observer with the target element
32
32
if ( targetElement ) {
33
- observerRef . current = new IntersectionObserver ( ( [ entry ] ) => setIsIntersecting ( entry . isIntersecting ) ) ;
33
+ // Fix for AWSUI-60898: In Firefox, IntersectionObserver instances inside an
34
+ // iframe context can't detect visibility changes caused by changes to elements
35
+ // outside the iframe (e.g. if an element wrapping the iframe is set to `display: none`).
36
+ let TopLevelIntersectionObserver = IntersectionObserver ;
37
+ try {
38
+ if ( window . top ) {
39
+ TopLevelIntersectionObserver = ( window . top as typeof window ) . IntersectionObserver ;
40
+ }
41
+ } catch {
42
+ // Tried to access a cross-origin iframe. Fall back to current IntersectionObserver.
43
+ }
44
+ observerRef . current = new TopLevelIntersectionObserver ( ( [ entry ] ) => setIsIntersecting ( entry . isIntersecting ) ) ;
34
45
observerRef . current . observe ( targetElement ) ;
35
46
}
36
47
} , [ ] ) ;
You can’t perform that action at this time.
0 commit comments