From 1f2fd8ac02c9d00f2ca1260424a00552d116accc Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Sun, 9 Nov 2025 21:53:06 +0800 Subject: [PATCH] Fix URIError from malformed cookies causing white screen on load (#2811) * Initial plan * Fix decodeURIComponent error in cookie parsing by adding try-catch Co-authored-by: whyour <22700758+whyour@users.noreply.github.com> * Add type annotation and logging to catch block per code review Co-authored-by: whyour <22700758+whyour@users.noreply.github.com> * Fix TypeScript errors in deps.ts - remove unused path parameter Co-authored-by: whyour <22700758+whyour@users.noreply.github.com> * Revert pnpm-lock.yaml to avoid unnecessary lockfile version upgrade Co-authored-by: whyour <22700758+whyour@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: whyour <22700758+whyour@users.noreply.github.com> --- back/loaders/deps.ts | 4 ++-- src/app.ts | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/back/loaders/deps.ts b/back/loaders/deps.ts index 767b9dfd..ade1bfeb 100644 --- a/back/loaders/deps.ts +++ b/back/loaders/deps.ts @@ -58,6 +58,6 @@ export default async (src: string = 'deps') => { }); watcher - .on('add', (path) => linkToNodeModule(src)) - .on('change', (path) => linkToNodeModule(src)); + .on('add', () => linkToNodeModule(src)) + .on('change', () => linkToNodeModule(src)); }; diff --git a/src/app.ts b/src/app.ts index 8aa3dfac..f18e4a19 100644 --- a/src/app.ts +++ b/src/app.ts @@ -7,11 +7,18 @@ export function rootContainer(container: any) { 'en': require('./locales/en-US.json'), 'zh': require('./locales/zh-CN.json'), }; - let currentLocale = intl.determineLocale({ - urlLocaleKey: 'lang', - cookieLocaleKey: 'lang', - localStorageLocaleKey: 'lang', - }).slice(0, 2); + let currentLocale: string; + try { + currentLocale = intl.determineLocale({ + urlLocaleKey: 'lang', + cookieLocaleKey: 'lang', + localStorageLocaleKey: 'lang', + }).slice(0, 2); + } catch (e: unknown) { + // Handle decodeURIComponent errors from malformed cookies + console.warn('Failed to determine locale from cookies:', e); + currentLocale = ''; + } if (!currentLocale || !Object.keys(locales).includes(currentLocale)) { currentLocale = 'zh';