discourse/app/views/application/_header.html.erb
Régis Hanol 3dfa25bc41
FIX: Respect forced color mode for logo on server-rendered pages (#37032)
When visiting pages that use the server-rendered header (404, password
reset, invites, etc.), the logo was always using the OS/browser
`prefers-color-scheme` preference instead of respecting the user's
explicit choice made via the interface color selector.

This happened because the `<source>` media query was hardcoded to
`(prefers-color-scheme: dark)`, ignoring the `forced_color_mode` cookie.

Now we use the existing `dark_elements_media_query` helper which returns
the appropriate value based on the user's preference:
- "none" when light mode is forced (hides dark logo)
- "all" when dark mode is forced (shows dark logo)
- "(prefers-color-scheme: dark)" for auto mode (respects OS)

This matches the behavior already implemented for the splash screen.

Ref - t/172056

**BEFORE**

<img width="1529" height="1220" alt="2026-01-09 @ 09 32 28"
src="https://github.com/user-attachments/assets/89c04e53-1360-442f-af27-af0ddc1f526c"
/>

**AFTER**

<img width="1529" height="1220" alt="2026-01-09 @ 09 32 19"
src="https://github.com/user-attachments/assets/75825cd1-9374-4e2f-b98b-e5ba5e4d72f0"
/>
2026-01-09 11:33:06 +01:00

34 lines
1.4 KiB
Text

<%= replace_plugin_html('server:simple-header') do %>
<header class="d-header">
<div class="wrap">
<div class="contents clearfix">
<div class="title">
<a href="<%= path "/" %>">
<%- if application_logo_url.present? %>
<picture>
<%- if application_logo_dark_url.present? %>
<source srcset="<%= application_logo_dark_url %>" media="<%= dark_elements_media_query %>" />
<%- end %>
<img src="<%= application_logo_url %>" alt="<%= SiteSetting.title %>" id="site-logo" />
</picture>
<%- else %>
<h2 id='site-text-logo'><%= SiteSetting.title %></h2>
<%- end %>
</a>
</div>
<div class="panel clearfix">
<%- unless current_user || local_assigns[:hide_auth_buttons] %>
<span class='header-buttons'>
<span class='auth-buttons'>
<%- if can_sign_up? %>
<a href="<%= path "/signup" %>" class='btn btn-text btn-primary btn-small sign-up-button'><%= I18n.t('sign_up') %></a>
<%- end %>
<a href="<%= path "/login" %>" class='btn btn-icon-text btn-primary btn-small login-button'><%= SvgSprite.raw_svg('user') %><%= I18n.t('log_in') %></a>
</span>
</span>
<%- end %>
</div>
</div>
</div>
</header>
<% end %>