Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4c1508a

Browse files
Simplify initialization logic
1 parent 5d013d6 commit 4c1508a

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

‎packages/gitbook/src/components/DocumentView/Tabs/DynamicTabs.tsx‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { getLocalStorageItem, setLocalStorageItem } from '@/lib/browser';
1717
import { tcls } from '@/lib/tailwind';
1818
import { Icon } from '@gitbook/icons';
1919
import { useRouter } from 'next/navigation';
20+
import { assert } from 'ts-essentials';
2021

2122
interface TabsState {
2223
activeIds: {
@@ -87,7 +88,7 @@ export function DynamicTabs(props: {
8788
);
8889
}, [id, tabs, tabsState]);
8990

90-
// Track is the tab has been touched by the user.
91+
// Track if the tab has been touched by the user.
9192
const touchedRef = useRef(false);
9293

9394
// To avoid issue with hydration, we only use the state from localStorage
@@ -133,13 +134,14 @@ export function DynamicTabs(props: {
133134
: prev.activeTitles,
134135
};
135136
});
136-
setInitialized(true);
137137
},
138138
[router, setTabsState, tabs, id]
139139
);
140140

141141
// When the hash changes, we try to select the tab containing the targetted element.
142142
React.useLayoutEffect(() => {
143+
setInitialized(true);
144+
143145
if (hash) {
144146
// First check if the hash matches a tab ID.
145147
const hashIsTab = tabs.some((tab) => tab.id === hash);
@@ -160,11 +162,6 @@ export function DynamicTabs(props: {
160162
}
161163

162164
selectTab(tabPanel.id, false);
163-
} else {
164-
const firstTab = tabs[0];
165-
if (firstTab) {
166-
selectTab(firstTab.id, false);
167-
}
168165
}
169166
}, [selectTab, tabs, hash]);
170167

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /