From cf4d66b28024bd6146de819c52bd2c38319caf34 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Sat, 10 Sep 2022 07:16:18 +0100 Subject: [PATCH] [Beta] Guard against a crash --- beta/src/components/MDX/Sandpack/NavigationBar.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/beta/src/components/MDX/Sandpack/NavigationBar.tsx b/beta/src/components/MDX/Sandpack/NavigationBar.tsx index 922982d6..ff7ac23d 100644 --- a/beta/src/components/MDX/Sandpack/NavigationBar.tsx +++ b/beta/src/components/MDX/Sandpack/NavigationBar.tsx @@ -53,7 +53,11 @@ export function NavigationBar({providedFiles}: {providedFiles: Array}) { hasJustToggledDropdown.current = false; return; } - const tabsWidth = tabsRef.current!.getBoundingClientRect().width; + if (tabsRef.current === null) { + // Some ResizeObserver calls come after unmount. + return; + } + const tabsWidth = tabsRef.current.getBoundingClientRect().width; const needsDropdown = tabsWidth >= containerWidth; if (needsDropdown !== showDropdown) { hasJustToggledDropdown.current = true;