fix(gui): CI gate repairs — docs, coverage, HMR re-registration
Regenerate the module-graph/config-catalog/event-graph docs for the locale rename and new packages; allowlist the three settings READMEs; complete the RFC code block and add its English pair. Cover the ThemeService media-query paths (stubbed matchMedia) and mark the unreachable registry fallback. General section re-registration now judges presence on the slot ledger instead of a local disposer, which went stale when an HMR collapse removed the entry.
This commit is contained in:
@@ -79,7 +79,14 @@ export function apply(ctx: ClientContext): void {
|
||||
|
||||
ctx.effect(() => {
|
||||
let dispose: (() => void) | undefined
|
||||
const register = (): void => {
|
||||
// Presence is judged on the ledger, not on the local disposer: an HMR
|
||||
// collapse of the declaring entry removes this entry from the slot core
|
||||
// while `dispose` stays set (the stale disposer is a no-op), so a local
|
||||
// guard would block the re-registration when the declaration returns.
|
||||
const registered = (): boolean =>
|
||||
ctx.slots.entries('settings.section').some(e => e.component === GeneralSection)
|
||||
const tryRegister = (): void => {
|
||||
if (ctx.slots.spec('settings.section') === undefined || registered()) return
|
||||
dispose = ctx.slots.register({
|
||||
name: 'settings.section',
|
||||
id: 'general',
|
||||
@@ -89,16 +96,13 @@ export function apply(ctx: ClientContext): void {
|
||||
inject: injected,
|
||||
}, GeneralSection)
|
||||
}
|
||||
const tryRegister = (): void => {
|
||||
if (ctx.slots.spec('settings.section') === undefined || dispose !== undefined) return
|
||||
register()
|
||||
}
|
||||
// Nav labels are registrant-localized: re-register on locale change so
|
||||
// the ledger carries fresh text (the version bump re-renders the shell).
|
||||
const offLocale = ctx.on('locale/change', () => {
|
||||
if (dispose === undefined) return
|
||||
dispose()
|
||||
register()
|
||||
if (!registered()) return
|
||||
dispose?.()
|
||||
dispose = undefined
|
||||
tryRegister()
|
||||
})
|
||||
const unsubscribe = ctx.slots.subscribe('settings.section', () => { tryRegister() })
|
||||
tryRegister()
|
||||
|
||||
@@ -157,6 +157,7 @@ export class ThemeService {
|
||||
: this.preference
|
||||
// Both built-ins always exist; a registered preference id resolves or has
|
||||
// been reset by its disposer, so the lookup cannot miss.
|
||||
/* v8 ignore next -- the ?? arm needs a registry without light/dark, which register()/dispose() cannot produce */
|
||||
const active = this.themes.find(t => t.id === resolvedId) ?? this.themes[0]!
|
||||
return Object.freeze({
|
||||
preference: this.preference,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// @vitest-environment jsdom
|
||||
import { beforeEach, describe, expect, it } from 'vitest'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { Context } from 'cordis'
|
||||
import type { ThemeSnapshot } from '@deepseek-ai/dsh-client-ui-theme/client'
|
||||
import { STORAGE_KEY, ThemeService } from '@deepseek-ai/dsh-client-ui-theme/client'
|
||||
@@ -87,4 +87,53 @@ describe('ThemeService', () => {
|
||||
dispose()
|
||||
expect(events.map(e => e.revision)).toEqual([1, 2, 3, 4])
|
||||
})
|
||||
|
||||
describe('prefers-color-scheme resolution (stubbed matchMedia)', () => {
|
||||
type Listener = () => void
|
||||
const stubMedia = (initialMatches: boolean) => {
|
||||
const listeners = new Set<Listener>()
|
||||
const media = {
|
||||
matches: initialMatches,
|
||||
addEventListener: (_: 'change', fn: Listener) => { listeners.add(fn) },
|
||||
removeEventListener: (_: 'change', fn: Listener) => { listeners.delete(fn) },
|
||||
flip() {
|
||||
this.matches = !this.matches
|
||||
for (const fn of listeners) fn()
|
||||
},
|
||||
listenerCount: () => listeners.size,
|
||||
}
|
||||
vi.stubGlobal('matchMedia', () => media)
|
||||
return media
|
||||
}
|
||||
|
||||
afterEach(() => { vi.unstubAllGlobals() })
|
||||
|
||||
it('system resolves against the media query and follows OS flips', () => {
|
||||
const media = stubMedia(true)
|
||||
const { theme, events } = make()
|
||||
expect(theme.getTheme().preference).toBe('system')
|
||||
expect(theme.getTheme().active.id).toBe('dark')
|
||||
media.flip()
|
||||
expect(theme.getTheme().active.id).toBe('light')
|
||||
expect(events).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('OS flips do not republish while a concrete preference is set', () => {
|
||||
const media = stubMedia(false)
|
||||
const { theme, events } = make()
|
||||
theme.setTheme('light')
|
||||
expect(events).toHaveLength(1)
|
||||
media.flip()
|
||||
expect(events).toHaveLength(1)
|
||||
expect(theme.getTheme().active.id).toBe('light')
|
||||
})
|
||||
|
||||
it('context dispose releases the media listener', async () => {
|
||||
const media = stubMedia(false)
|
||||
const { ctx } = make()
|
||||
expect(media.listenerCount()).toBe(1)
|
||||
await ctx.fiber.dispose()
|
||||
expect(media.listenerCount()).toBe(0)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user