# All files / src/SuperSelect useVirtuosoResizeErrorFix.ts

27.27% Statements 3/11
0% Branches 0/1
0% Functions 0/4
20% Lines 2/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    232x

    2x

     import React from 'react'

    export const useVirtuosoResizeErrorFix = () => {
      // this fix is borrowed from the official Virtuoso+React Beautiful DnD sandbox implementation
      // https://virtuoso.dev/react-beautiful-dnd/
      React.useEffect(() => {
        const targetErrors = [
          'ResizeObserver loop completed with undelivered notifications.',
          'ResizeObserver loop limit exceeded',
        ]
        const onWindowError = (e: WindowEventMap['error']) => {
          Iif (targetErrors.includes(e.message)) {
            e.stopImmediatePropagation()
          }
        }
        window.addEventListener('error', onWindowError)

        return () => {
          window.removeEventListener('error', onWindowError)
        }
      }, [])
    }