mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-23 05:42:33 +09:00
Fix relative-time error and improve global error handler (#37241)
1. Fixes: #37239 2. Enhance global error message to show stack trace on click --------- Signed-off-by: silverwind <me@silverwind.io> Signed-off-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: Claude (Opus 4.7) <noreply@anthropic.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -109,6 +109,18 @@ test('respects lang from parent element', async () => {
|
||||
expect(getText(el)).toBe('vor 3 Tagen');
|
||||
});
|
||||
|
||||
test('falls back when navigator.language is invalid', async () => {
|
||||
vi.spyOn(navigator, 'language', 'get').mockReturnValue('undefined');
|
||||
try {
|
||||
const el = document.createElement('relative-time');
|
||||
el.setAttribute('datetime', new Date(Date.now() - 3 * 60 * 1000).toISOString());
|
||||
await Promise.resolve();
|
||||
expect(getText(el)).toBe('3 minutes ago');
|
||||
} finally {
|
||||
vi.restoreAllMocks();
|
||||
}
|
||||
});
|
||||
|
||||
test('switches to datetime with P1D threshold', async () => {
|
||||
const el = createRelativeTime(new Date(Date.now() - 2 * 24 * 60 * 60 * 1000).toISOString(), {
|
||||
lang: 'en-US',
|
||||
|
||||
@@ -258,13 +258,13 @@ class RelativeTime extends HTMLElement {
|
||||
}
|
||||
|
||||
get #lang(): string {
|
||||
const lang = this.closest('[lang]')?.getAttribute('lang');
|
||||
if (lang) {
|
||||
for (const candidate of [this.closest('[lang]')?.getAttribute('lang'), navigator.language]) {
|
||||
if (!candidate) continue;
|
||||
try {
|
||||
return new Intl.Locale(lang).toString();
|
||||
} catch { /* invalid locale, fall through */ }
|
||||
return String(new Intl.Locale(candidate));
|
||||
} catch {}
|
||||
}
|
||||
return navigator.language ?? 'en';
|
||||
return 'en';
|
||||
}
|
||||
|
||||
get second(): 'numeric' | '2-digit' | undefined {
|
||||
|
||||
Reference in New Issue
Block a user