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>
This commit is contained in:
Copilot 2025-11-09 21:53:06 +08:00 committed by GitHub
parent 06aa07329f
commit 1f2fd8ac02
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 7 deletions

View File

@ -58,6 +58,6 @@ export default async (src: string = 'deps') => {
}); });
watcher watcher
.on('add', (path) => linkToNodeModule(src)) .on('add', () => linkToNodeModule(src))
.on('change', (path) => linkToNodeModule(src)); .on('change', () => linkToNodeModule(src));
}; };

View File

@ -7,11 +7,18 @@ export function rootContainer(container: any) {
'en': require('./locales/en-US.json'), 'en': require('./locales/en-US.json'),
'zh': require('./locales/zh-CN.json'), 'zh': require('./locales/zh-CN.json'),
}; };
let currentLocale = intl.determineLocale({ let currentLocale: string;
try {
currentLocale = intl.determineLocale({
urlLocaleKey: 'lang', urlLocaleKey: 'lang',
cookieLocaleKey: 'lang', cookieLocaleKey: 'lang',
localStorageLocaleKey: 'lang', localStorageLocaleKey: 'lang',
}).slice(0, 2); }).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)) { if (!currentLocale || !Object.keys(locales).includes(currentLocale)) {
currentLocale = 'zh'; currentLocale = 'zh';