Skip to content

Commit 39f2893

Browse files
authored
docs: fix runtime error occuring with code tabs (medusajs#13873)
1 parent 9f154c3 commit 39f2893

File tree

1 file changed

+7
-4
lines changed
  • www/packages/docs-ui/src/components/CodeTabs

1 file changed

+7
-4
lines changed

www/packages/docs-ui/src/components/CodeTabs/index.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export const CodeTabs = ({
175175
group,
176176
})
177177

178-
const tabRefs: (HTMLButtonElement | null)[] = useMemo(() => [], [])
178+
const tabRefs = useRef<(HTMLButtonElement | null)[]>([])
179179
const codeTabSelectorRef = useRef<HTMLSpanElement | null>(null)
180180
const codeTabsWrapperRef = useRef<HTMLDivElement | null>(null)
181181

@@ -221,8 +221,8 @@ export const CodeTabs = ({
221221
)
222222

223223
useEffect(() => {
224-
if (codeTabSelectorRef?.current && tabRefs.length) {
225-
const selectedTabElm = tabRefs.find(
224+
if (codeTabSelectorRef?.current && tabRefs.current.length) {
225+
const selectedTabElm = tabRefs.current.find(
226226
(tab) => tab?.getAttribute("aria-selected") === "true"
227227
)
228228
if (selectedTabElm) {
@@ -250,6 +250,9 @@ export const CodeTabs = ({
250250
}
251251
}, [selectedTab])
252252

253+
// Reset tabRefs array before each render
254+
tabRefs.current = []
255+
253256
return (
254257
<div
255258
className={clsx(
@@ -299,7 +302,7 @@ export const CodeTabs = ({
299302
{...(typeof child.props === "object" ? child.props : {})}
300303
changeSelectedTab={changeSelectedTab}
301304
pushRef={(tabButton: HTMLButtonElement | null) =>
302-
tabRefs.push(tabButton)
305+
tabRefs.current.push(tabButton)
303306
}
304307
blockStyle={blockStyle}
305308
isSelected={

0 commit comments

Comments
 (0)