From 533af5dcee61ca1ec1eb2f8cfbdea87d249b0bcc Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 10 Jun 2025 15:25:24 +0200 Subject: [PATCH] [Glitch] Fix crash in `/about` when server returns cached rules without `translations` attribute Port c7277018394335f5950e1f235b0995c53b129f85 to glitch-soc Signed-off-by: Claire --- .../glitch/features/about/components/rules.tsx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/javascript/flavours/glitch/features/about/components/rules.tsx b/app/javascript/flavours/glitch/features/about/components/rules.tsx index 2ba95fedb3..bb1350f068 100644 --- a/app/javascript/flavours/glitch/features/about/components/rules.tsx +++ b/app/javascript/flavours/glitch/features/about/components/rules.tsx @@ -29,7 +29,7 @@ interface BaseRule { interface Rule extends BaseRule { id: string; - translations: Record; + translations?: Record; } export const RulesSection: FC = ({ isLoading = false }) => { @@ -113,15 +113,23 @@ const rulesSelector = createSelector( (rules, locale): Rule[] => { return rules.map((rule) => { const translations = rule.translations; - if (translations[locale]) { - rule.text = translations[locale].text; - rule.hint = translations[locale].hint; + + // Handle cached responses from earlier versions + if (!translations) { + return rule; } + const partialLocale = locale.split('-')[0]; if (partialLocale && translations[partialLocale]) { rule.text = translations[partialLocale].text; rule.hint = translations[partialLocale].hint; } + + if (translations[locale]) { + rule.text = translations[locale].text; + rule.hint = translations[locale].hint; + } + return rule; }); },