Name: [FIX] viin_brand_web: resolve dark mode from the user, not the browser

State: Failed finished in 70m

PR State: merged

PR Author: David Tran

PR Author Email:

PR: #682

Committer: David Tran

Committer Email: david.tran@tvtmarine.com

Commit: 5343e24405bfa318e9b09509fec5ae64cf76ed85

Description:

                                            [FIX] viin_brand_web: resolve dark mode from the user, not the browser

Two reported symptoms, one root cause: the code treated the
`color_scheme` cookie as if it were a preference, when it is a cache of
a resolution. A preference belongs to a USER; this cookie belongs to a
BROWSER and outlives the session that wrote it.

Symptom 1 - another person's cookie decided your scheme. color_scheme()
ranked the cookie above the stored preference, so on a shared browser
the last user's choice served the next user the wrong compiled bundle.
Measured before the change: preference 'light' plus a
`color_scheme=dark` cookie rendered data-bs-theme="dark", with the dark
bundle referenced.

Symptom 2 - "System" always came up light. setScheme('auto') writes the
matchMedia-resolved scheme to the cookie, then awaits an ORM write whose
own handler expired that very cookie. Measured: the write response
carried `color_scheme=; Max-Age=0; Path=/`, the host-only cookie left
the jar, and the reload that follows then found no cookie, fell through
to core's `return "light"`, and served light whatever the device said.
The client re-resolved afterwards, so the user saw light, a half-flip,
and dark only on the next reload.

The resolution order is now the user's own explicit light/dark
preference, then the cookie, then super(). The cookie keeps its place
above super() because 'auto' is the one case the server genuinely cannot
decide: it cannot read the device preference, so the client resolves it
and caches the effective light|dark there. For the same reason writing
'auto' no longer expires the cookie - that would throw away the only
copy of the answer the imminent reload needs.

That cookie is also core's own client-side source of truth for dark
mode: core reads it for graph colours, the colour picker, the ace editor
and the pdf.js viewer. Expiring it did not merely mis-pick a bundle, it
left every one of those drawing light-mode colours inside a dark UI.

Two tests pinned the old behaviour and are replaced, not loosened. One
asserted the cookie "overrides everything"; it now asserts an explicit
preference survives a contrary cookie, with a sibling covering the
'auto' case where the cookie is authoritative. The other asserted the
switch to 'auto' expires the cookie, citing the old precedence as its
reason; it now asserts the cached resolution is left alone. Both were
protecting a defect, so changing them is a corrected contract, not an
expectation bent to match output.

Signed-off-by: David Tran <david.tran@tvtmarine.com>
                                            

Branch: 19.0

Age:

Up-time: