Skip to content

Commit 0a95b97

Browse files
committed
refactor: update CloudVersionSelect to handle client-side rendering
- Introduced a new state variable to manage client-side rendering, ensuring the currentCloudVersion.label is displayed correctly after the component mounts. - Retained the labelRef for potential future use while simplifying the rendering logic for better clarity.
1 parent 923452f commit 0a95b97

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/components/Layout/HeaderAction.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ const LangSwitch = (props: {
215215
onClick={toggleLanguage(Locale.zh)}
216216
disableRipple
217217
selected={language === Locale.zh}
218-
disabled={!supportedLocales.includes(Locale.zh) || !isClassic}
218+
disabled={!supportedLocales.includes(Locale.zh)}
219219
>
220220
<Typography component="span" color={theme.palette.carbon[900]}>
221221
<Trans i18nKey="lang.zh" />

src/components/Layout/VersionSelect/CloudVersionSelect.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Box, Typography } from "@mui/material";
1010
import { Chip } from "@mui/material";
1111
import { CLOUD_MODE_KEY, useCloudPlan } from "shared/useCloudPlan";
1212
import { VersionSelectButton, VersionSelectMenu } from "./SharedSelect";
13-
import { useEffect, useRef } from "react";
13+
import { useEffect, useRef, useState } from "react";
1414

1515
export const CLOUD_PLAN_LABEL_ELEMENT_ID = "cloud-plan-label";
1616

@@ -131,13 +131,10 @@ export default function CloudVersionSelect(props: VersionSelectProps) {
131131
const [open, setOpen] = React.useState<boolean>(false);
132132
const handleClick = () => setOpen(true);
133133
const handleClose = () => setOpen(false);
134-
// const labelRef = useRef<HTMLSpanElement>(null);
134+
const labelRef = useRef<HTMLSpanElement>(null);
135+
const [isClient, setIsClient] = useState(false);
135136

136-
// useEffect(() => {
137-
// if (labelRef.current && currentCloudVersion.label) {
138-
// labelRef.current.textContent = currentCloudVersion.label as string;
139-
// }
140-
// }, [currentCloudVersion]);
137+
useEffect(() => setIsClient(true), []);
141138

142139
return (
143140
<>
@@ -151,7 +148,11 @@ export default function CloudVersionSelect(props: VersionSelectProps) {
151148
lineHeight: "1.25rem",
152149
}}
153150
>
154-
{currentCloudVersion.label}
151+
{isClient ? (
152+
currentCloudVersion.label
153+
) : (
154+
<span id={CLOUD_PLAN_LABEL_ELEMENT_ID} ref={labelRef} />
155+
)}
155156
</Typography>
156157
{currentCloudVersion?.icon}
157158
</Box>

0 commit comments

Comments
 (0)