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 64ed46c

Browse files
Simplify initialization logic
1 parent 5d013d6 commit 64ed46c

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export function DynamicTabs(props: {
8787
);
8888
}, [id, tabs, tabsState]);
8989

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

9393
// To avoid issue with hydration, we only use the state from localStorage
@@ -133,13 +133,14 @@ export function DynamicTabs(props: {
133133
: prev.activeTitles,
134134
};
135135
});
136-
setInitialized(true);
137136
},
138137
[router, setTabsState, tabs, id]
139138
);
140139

141140
// When the hash changes, we try to select the tab containing the targetted element.
142141
React.useLayoutEffect(() => {
142+
setInitialized(true);
143+
143144
if (hash) {
144145
// First check if the hash matches a tab ID.
145146
const hashIsTab = tabs.some((tab) => tab.id === hash);
@@ -160,11 +161,6 @@ export function DynamicTabs(props: {
160161
}
161162

162163
selectTab(tabPanel.id, false);
163-
} else {
164-
const firstTab = tabs[0];
165-
if (firstTab) {
166-
selectTab(firstTab.id, false);
167-
}
168164
}
169165
}, [selectTab, tabs, hash]);
170166

0 commit comments

Comments
(0)

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