Browse Source

fix(highlights): Set column count after ref defined (#71197)

Scott Cooper 9 months ago
parent
commit
ea0aa3db9f
1 changed files with 8 additions and 1 deletions
  1. 8 1
      static/app/components/events/eventTags/util.tsx

+ 8 - 1
static/app/components/events/eventTags/util.tsx

@@ -1,4 +1,4 @@
-import {type RefObject, useCallback, useState} from 'react';
+import {type RefObject, useCallback, useLayoutEffect, useState} from 'react';
 import {useResizeObserver} from '@react-aria/utils';
 
 import {useLocation} from 'sentry/utils/useLocation';
@@ -189,6 +189,13 @@ export function useIssueDetailsColumnCount(elementRef: RefObject<HTMLElement>):
 
   const [columnCount, setColumnCount] = useState(calculateColumnCount());
 
+  // If the ref was undefined, calculate the column count again
+  useLayoutEffect(() => {
+    if (elementRef.current) {
+      setColumnCount(calculateColumnCount());
+    }
+  }, [calculateColumnCount, elementRef]);
+
   const onResize = useCallback(() => {
     const count = calculateColumnCount();
     setColumnCount(count);