Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/Aspire.Dashboard/wwwroot/js/app-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function updateTheme(specifiedTheme) {
* @returns {string}
*/
export function getThemeCookieValue() {
return getCookieValue(currentThemeCookieName) ?? themeSettingSystem;
return getCookieValue(currentThemeCookieName);
}

export function getCurrentTheme() {
Expand All @@ -61,7 +61,10 @@ function getSystemTheme() {
* @param {string} theme
*/
function setThemeCookie(theme) {
document.cookie = `${currentThemeCookieName}=${theme}`;
// Cookie will expire after 1 year. Using a much larger value won't have an impact because
// Chrome limits expiration to 400 days: https://developer.chrome.com/blog/cookie-max-age-expires
// The cookie is reset when the dashboard loads to creating a sliding expiration.
document.cookie = `${currentThemeCookieName}=${theme}; expires=${new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 365).toGMTString()}`;
}

/**
Expand Down Expand Up @@ -260,6 +263,12 @@ function initializeTheme() {
const effectiveTheme = getEffectiveTheme(themeCookieValue);

applyTheme(effectiveTheme);

// If a theme cookie has been set then set it again on page load.
// This updates the cookie expiration date and creates a sliding expiration.
if (themeCookieValue) {
setThemeCookie(themeCookieValue);
}
}

createAdditionalDesignTokens();
Expand Down