Skip to content

Commit ba30f46

Browse files
authored
🐛 fix: TypewriterEffect not refreshing on language change (lobehub#11657)
Add locale key to TypewriterEffect components to force re-render when language changes
1 parent 5858cd1 commit ba30f46

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

src/app/[variants]/(desktop)/desktop-onboarding/components/LobeMessage.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Flexbox, type FlexboxProps, Text } from '@lobehub/ui';
22
import { TypewriterEffect, type TypewriterEffectProps } from '@lobehub/ui/awesome';
33
import { LoadingDots } from '@lobehub/ui/chat';
44
import { memo } from 'react';
5+
import { useTranslation } from 'react-i18next';
56

67
import { ProductLogo } from '@/components/Branding';
78

@@ -11,6 +12,9 @@ interface LobeMessageProps extends Omit<FlexboxProps, 'children'> {
1112
}
1213

1314
const LobeMessage = memo<LobeMessageProps>(({ sentences, fontSize = 24, ...rest }) => {
15+
const { i18n } = useTranslation();
16+
const locale = i18n.language;
17+
1418
return (
1519
<Flexbox gap={8} {...rest}>
1620
<ProductLogo size={fontSize * 2} />
@@ -21,6 +25,7 @@ const LobeMessage = memo<LobeMessageProps>(({ sentences, fontSize = 24, ...rest
2125
deletePauseDuration={1000}
2226
deletingSpeed={32}
2327
hideCursorWhileTyping={'afterTyping'}
28+
key={locale}
2429
pauseDuration={16_000}
2530
sentences={sentences}
2631
typingSpeed={64}

src/app/[variants]/(desktop)/desktop-onboarding/features/WelcomeStep.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ interface WelcomeStepProps {
1717
}
1818

1919
const WelcomeStep = memo<WelcomeStepProps>(({ onNext }) => {
20-
const { t } = useTranslation('onboarding');
20+
const { t, i18n } = useTranslation('onboarding');
21+
const locale = i18n.language;
2122
const updateGeneralConfig = useUserStore((s) => s.updateGeneralConfig);
2223

2324
const handleNext = () => {
@@ -53,6 +54,7 @@ const WelcomeStep = memo<WelcomeStepProps>(({ onNext }) => {
5354
deletePauseDuration={1000}
5455
deletingSpeed={32}
5556
hideCursorWhileTyping={'afterTyping'}
57+
key={locale}
5658
pauseDuration={16_000}
5759
sentences={[
5860
t('telemetry.title', { name: 'Lobe AI' }),

src/app/[variants]/(main)/home/features/WelcomeText/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { memo, useMemo } from 'react';
77
import { useTranslation } from 'react-i18next';
88

99
const WelcomeText = memo(() => {
10-
const { t } = useTranslation('welcome');
10+
const { t, i18n } = useTranslation('welcome');
11+
const locale = i18n.language;
1112

1213
const sentences = useMemo(() => {
1314
const messages = t('welcomeMessages', { returnObjects: true }) as Record<string, string>;
@@ -28,6 +29,7 @@ const WelcomeText = memo(() => {
2829
deletePauseDuration={1000}
2930
deletingSpeed={32}
3031
hideCursorWhileTyping={'afterTyping'}
32+
key={locale}
3133
pauseDuration={16_000}
3234
sentences={sentences}
3335
typingSpeed={64}

src/app/[variants]/onboarding/components/LobeMessage.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Flexbox, type FlexboxProps, Text } from '@lobehub/ui';
22
import { TypewriterEffect, type TypewriterEffectProps } from '@lobehub/ui/awesome';
33
import { LoadingDots } from '@lobehub/ui/chat';
44
import { memo } from 'react';
5+
import { useTranslation } from 'react-i18next';
56

67
import { ProductLogo } from '@/components/Branding';
78

@@ -11,6 +12,9 @@ interface LobeMessageProps extends Omit<FlexboxProps, 'children'> {
1112
}
1213

1314
const LobeMessage = memo<LobeMessageProps>(({ sentences, fontSize = 24, ...rest }) => {
15+
const { i18n } = useTranslation();
16+
const locale = i18n.language;
17+
1418
return (
1519
<Flexbox gap={8} {...rest}>
1620
<ProductLogo size={fontSize * 2} />
@@ -21,6 +25,7 @@ const LobeMessage = memo<LobeMessageProps>(({ sentences, fontSize = 24, ...rest
2125
deletePauseDuration={1000}
2226
deletingSpeed={32}
2327
hideCursorWhileTyping={'afterTyping'}
28+
key={locale}
2429
pauseDuration={16_000}
2530
sentences={sentences}
2631
typingSpeed={64}

src/app/[variants]/onboarding/features/TelemetryStep.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ interface TelemetryStepProps {
1919
}
2020

2121
const TelemetryStep = memo<TelemetryStepProps>(({ onNext }) => {
22-
const { t } = useTranslation('onboarding');
22+
const { t, i18n } = useTranslation('onboarding');
23+
const locale = i18n.language;
2324
const [check, setCheck] = useState(true);
2425
const [isNavigating, setIsNavigating] = useState(false);
2526
const isNavigatingRef = useRef(false);
@@ -63,6 +64,7 @@ const TelemetryStep = memo<TelemetryStepProps>(({ onNext }) => {
6364
deletePauseDuration={1000}
6465
deletingSpeed={32}
6566
hideCursorWhileTyping={'afterTyping'}
67+
key={locale}
6668
pauseDuration={16_000}
6769
sentences={[
6870
t('telemetry.title', { name: 'Lobe AI' }),

0 commit comments

Comments
 (0)