fix(theme): persist switcher accent for SSR
Quality / quality (ubuntu-latest) (push) Failing after 9m48s
Quality / quality (windows-latest) (push) Canceled after 0s

This commit is contained in:
2026-08-12 21:17:20 +05:30
parent effed1c3cf
commit dd9b7a289a
8 changed files with 11 additions and 25 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/cli", "name": "@wrnexus/cli",
"version": "0.8.27", "version": "0.8.28",
"type": "module", "type": "module",
"main": "src/index.ts", "main": "src/index.ts",
"exports": { "exports": {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/dev-server", "name": "@wrnexus/dev-server",
"version": "0.8.26", "version": "0.8.27",
"type": "module", "type": "module",
"main": "src/index.ts", "main": "src/index.ts",
"exports": { "exports": {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/styles", "name": "@wrnexus/styles",
"version": "0.8.12", "version": "0.8.13",
"type": "module", "type": "module",
"main": "src/index.ts", "main": "src/index.ts",
"exports": { "exports": {
-15
View File
@@ -745,17 +745,6 @@ export function renderThemeRuntime(theme: ResolvedTheme): string {
window.dispatchEvent(new CustomEvent("wrnexus:accent-changed",{detail:{accent:null}})); window.dispatchEvent(new CustomEvent("wrnexus:accent-changed",{detail:{accent:null}}));
} }
function syncSharedAccent(){
var cookieAccent=readCookie(ACCENT_COOKIE);
var next=cookieAccent&&ACCENTS.indexOf(cookieAccent)>=0?cookieAccent:DEFAULT_ACCENT;
var current=el.getAttribute("data-accent");
if(next===current)return;
if(next)el.setAttribute("data-accent",next);else el.removeAttribute("data-accent");
syncStylesheet(getTheme(),next);
syncAccentButtons(document);
window.dispatchEvent(new CustomEvent("wrnexus:accent-changed",{detail:{accent:next}}));
}
function bind(root){ function bind(root){
var target=root||document; var target=root||document;
@@ -814,10 +803,6 @@ export function renderThemeRuntime(theme: ResolvedTheme): string {
}; };
window.addEventListener("wrnexus:navigated",function(){bind(document);}); window.addEventListener("wrnexus:navigated",function(){bind(document);});
window.addEventListener("focus",syncSharedAccent);
window.addEventListener("pageshow",syncSharedAccent);
document.addEventListener("visibilitychange",function(){if(!document.hidden)syncSharedAccent();});
window.setInterval(syncSharedAccent,1000);
if(document.readyState==="loading"){ if(document.readyState==="loading"){
document.addEventListener("DOMContentLoaded",function(){bind(document);}); document.addEventListener("DOMContentLoaded",function(){bind(document);});
}else{ }else{
+1 -2
View File
@@ -58,8 +58,7 @@ describe("theme accents", () => {
expect(runtime).toContain('"domain":"localhost"'); expect(runtime).toContain('"domain":"localhost"');
expect(runtime).toContain("deleteCookie(ACCENT_COOKIE);"); expect(runtime).toContain("deleteCookie(ACCENT_COOKIE);");
expect(runtime).toContain("writeCookie(ACCENT_COOKIE,name,ACCENT_COOKIE_OPTIONS)"); expect(runtime).toContain("writeCookie(ACCENT_COOKIE,name,ACCENT_COOKIE_OPTIONS)");
expect(runtime).toContain('window.addEventListener("focus",syncSharedAccent)'); expect(runtime).not.toContain("setInterval(syncSharedAccent");
expect(runtime).toContain("window.setInterval(syncSharedAccent,1000)");
}); });
}); });
test("live document accent has priority over cookie and default", () => { test("live document accent has priority over cookie and default", () => {
@@ -30,6 +30,8 @@ size: string = "default"
functions { functions {
client function choose(type, value) { client function choose(type, value) {
if (type === "color") window.wrnAccent?.set(value)
if (type === "theme") window.wrnTheme?.set(value)
output[type]({ value: value }) output[type]({ value: value })
} }
} }
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/ui", "name": "@wrnexus/ui",
"version": "0.8.14", "version": "0.8.15",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "src/index.ts", "main": "src/index.ts",
+4 -4
View File
@@ -374,10 +374,10 @@ test("navbar hover menu stays open while the pointer crosses into its panel", as
}); });
test("preference switcher keeps only one popover open and closes outside", async () => { test("preference switcher keeps only one popover open and closes outside", async () => {
const html = await renderComponent( const source = readFileSync(uiComponentPath("PreferenceSwitcher"), "utf8");
readFileSync(uiComponentPath("PreferenceSwitcher"), "utf8"), const html = await renderComponent(source, {});
{}, expect(source).toContain("window.wrnAccent?.set(value)");
); expect(source).toContain("window.wrnTheme?.set(value)");
const dom = mountHtml(html); const dom = mountHtml(html);
const menus = Array.from(dom.querySelectorAll(".wrn-preferences__menu")) as HTMLDetailsElement[]; const menus = Array.from(dom.querySelectorAll(".wrn-preferences__menu")) as HTMLDetailsElement[];
const DomEvent = (dom.window as { Event: typeof Event }).Event; const DomEvent = (dom.window as { Event: typeof Event }).Event;