fix: fall back to original language on post redirect

This commit is contained in:
TerryM
2026-06-04 17:50:03 +08:00
parent ec98ff5a03
commit 1fcf2ea46d
9 changed files with 75 additions and 8 deletions

View File

@@ -0,0 +1,43 @@
---
title: "Favorite Other-Language Post Redirect — Quick Fix"
type: quick-fix
date: 2026-06-04
---
# Favorite Other-Language Post Redirect — Quick Fix
## Bug
When the user is on a UI language (e.g. Chinese) and clicks a favorited post that does not have a translation in that language, the post page silently redirected to `/browse` and the user could not see the post.
## Root Cause
`src/pages/PostRedirect/index.tsx` requested `GET /api/posts/{id}?lang=<ui-lang>`. The backend returns `404` when the post has no translation in the requested language. The redirect's `.catch` silently sent the user to `/browse`, hiding the post entirely.
## Fix
`PostRedirect` now retries without the `lang` parameter on failure. If the post exists in any language, the user is taken to the post anyway, and a toast tells them the post is shown in its original language because the selected language is unavailable. If the retry also fails (post truly missing), behavior is unchanged: redirect to `/browse`.
A new i18n key `postShownInOriginalLanguage` was added in all 7 locales.
### Files Modified
- `src/pages/PostRedirect/index.tsx` — added language fallback fetch, toast notice.
- `src/locales/zh-CN.ts` — added `postShownInOriginalLanguage`.
- `src/locales/en.ts` — added `postShownInOriginalLanguage`.
- `src/locales/ja.ts` — added `postShownInOriginalLanguage`.
- `src/locales/ko.ts` — added `postShownInOriginalLanguage`.
- `src/locales/vi.ts` — added `postShownInOriginalLanguage`.
- `src/locales/id.ts` — added `postShownInOriginalLanguage`.
- `src/locales/ms.ts` — added `postShownInOriginalLanguage`.
## Verification
- `npx tsc --noEmit`
- `npm run format:check`
- `npm test` (13 files, 49 tests)
- Staging curl confirmed: `GET /api/posts/{id}?lang=en` returns `404` for a Chinese-only post, while `GET /api/posts/{id}` returns `200` with the post in its source language.
## Notes
No deploy was performed.