Skip to content

Commit 9c6bc1f

Browse files
authored
Update sentry sample rate (#650)
* chore: adjust tracesSampleRate in Sentry configuration for improved performance * fix: improve node removal safety in useTotalContributors hook * fix: correct dependency array in TabContentDetector to ensure proper rendering behavior * fix: enhance TabContentDetector to prevent duplicate rendering of tabs - Added renderedTabs prop to SimpleTab and TabContentDetector components. - Updated useEffect in TabContentDetector to check if the tab has already been rendered, ensuring proper rendering behavior and preventing duplicate calls to onRendered. * feat: update HeaderNav to conditionally render cloud plan links - Integrated useCloudPlan hook to retrieve the current cloud plan. - Modified navigation links in HeaderNavStack and HeaderNavStackMobile to dynamically adjust the URL based on the cloud plan, enhancing user experience. * fix: correct optional chaining in filterRightToc function - Removed optional chaining for item.items to ensure proper filtering of nested items in the filterRightToc function, enhancing functionality.
1 parent a33d630 commit 9c6bc1f

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed

sentry.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ Sentry.init({
55
dsn: process.env.GATSBY_SENTRY_DSN,
66
integrations: [Sentry.browserTracingIntegration()],
77

8-
tracesSampleRate: 0.1,
8+
tracesSampleRate: 0.01,
99
});

src/components/Contributors/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,13 @@ export const useTotalContributors = (
237237
return;
238238
}
239239
ReactDOM.unmountComponentAtNode(appendedNode);
240-
appendedNode?.parentNode?.removeChild(appendedNode);
240+
// Check if the node is still a child of its parent before removing
241+
if (
242+
appendedNode.parentNode &&
243+
appendedNode.parentNode.contains(appendedNode)
244+
) {
245+
appendedNode.parentNode.removeChild(appendedNode);
246+
}
241247
};
242248
}, [totalContributors]);
243249

src/components/Layout/HeaderNav.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { BuildType } from "shared/interface";
2323
import { GTMEvent, gtmTrack } from "shared/utils/gtm";
2424

2525
import TiDBLogo from "media/logo/tidb-logo-withtext.svg";
26+
import { CLOUD_MODE_KEY, useCloudPlan } from "shared/useCloudPlan";
2627

2728
// `pageUrl` comes from server side render (or build): gatsby/path.ts/generateUrl
2829
// it will be `undefined` in client side render
@@ -46,6 +47,7 @@ export default function HeaderNavStack(props: {
4647
}) {
4748
const { language, t } = useI18next();
4849
const selectedItem = useSelectedNavItem(language, props.pageUrl);
50+
const { cloudPlan } = useCloudPlan();
4951

5052
return (
5153
<Stack
@@ -64,7 +66,11 @@ export default function HeaderNavStack(props: {
6466
<NavItem
6567
selected={selectedItem === "tidbcloud"}
6668
label={t("navbar.cloud")}
67-
to={`/tidbcloud`}
69+
to={
70+
cloudPlan === "dedicated"
71+
? `/tidbcloud`
72+
: `/tidbcloud/${cloudPlan}?${CLOUD_MODE_KEY}=${cloudPlan}`
73+
}
6874
/>
6975
)}
7076

@@ -161,7 +167,7 @@ export function HeaderNavStackMobile(props: { buildType?: BuildType }) {
161167
const theme = useTheme();
162168
const { language, t } = useI18next();
163169
const selectedItem = useSelectedNavItem(language);
164-
170+
const { cloudPlan } = useCloudPlan();
165171
const open = Boolean(anchorEl);
166172
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
167173
setAnchorEl(event.currentTarget);
@@ -240,7 +246,11 @@ export function HeaderNavStackMobile(props: { buildType?: BuildType }) {
240246
>
241247
<LinkComponent
242248
isI18n
243-
to="/tidbcloud"
249+
to={
250+
cloudPlan === "dedicated"
251+
? `/tidbcloud`
252+
: `/tidbcloud/${cloudPlan}?${CLOUD_MODE_KEY}=${cloudPlan}`
253+
}
244254
style={{ width: "100%" }}
245255
onClick={() =>
246256
gtmTrack(GTMEvent.ClickHeadNav, {

src/components/Layout/Navigation/RightNav.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export default function RightNav(props: RightNavProps) {
8383
headingIds.push(id);
8484
}
8585
}
86-
if (item.items) {
86+
if (item?.items) {
8787
collectIds(item.items);
8888
}
8989
});

src/components/MDXComponents/SimpleTab.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export function SimpleTab({
104104
key={id}
105105
id={id}
106106
activeTab={activeTab}
107+
renderedTabs={renderedTabs}
107108
onRendered={() => {
108109
setRenderedTabs((prev) => {
109110
if (prev.includes(id)) {
@@ -135,19 +136,25 @@ export const TabContentDetector = ({
135136
children,
136137
id,
137138
activeTab,
139+
renderedTabs,
138140
onRendered,
139141
}: {
140142
children: ReactElement;
141143
id: string;
142144
activeTab: string;
145+
renderedTabs: string[];
143146
onRendered: (id: string) => void;
144147
}) => {
145148
const ref = useRef<HTMLDivElement>(null);
146149
useEffect(() => {
147-
if (ref.current && ref.current.children.length > 0) {
150+
if (
151+
ref.current &&
152+
ref.current.children.length > 0 &&
153+
!renderedTabs.includes(id)
154+
) {
148155
onRendered(id);
149156
}
150-
}, []);
157+
});
151158
return (
152159
<div ref={ref} key={id} className={clsx({ [hidden]: activeTab !== id })}>
153160
{children}

0 commit comments

Comments
 (0)