release: WRNexusJS 0.5.11
This commit is contained in:
@@ -40,14 +40,16 @@ import { renderDocument, type RenderScript, type ScriptAsset } from "@wrnexus/ss
|
||||
import type { ClientRuntimeDefinition } from "@wrnexus/plugin";
|
||||
import { runtimeScriptsForMarkup } from "./plugin-assets.ts";
|
||||
import {
|
||||
ACCENT_COOKIE,
|
||||
THEME_COOKIE,
|
||||
THEME_CSS_HREF,
|
||||
THEME_JS_HREF,
|
||||
resolveAccentName,
|
||||
resolveThemeName,
|
||||
type ResolvedTheme,
|
||||
type MobileConfig,
|
||||
type PwaConfig,
|
||||
type ObservabilityConfig,
|
||||
type PwaConfig,
|
||||
type ResolvedTheme,
|
||||
type TenancyConfig,
|
||||
} from "@wrnexus/styles";
|
||||
import {
|
||||
@@ -587,16 +589,37 @@ export const HMR_CLIENT_JS = `
|
||||
function applyHtml(html) {
|
||||
pendingSync = false;
|
||||
var doc = new DOMParser().parseFromString(html, "text/html");
|
||||
if (doc.title) document.title = doc.title;
|
||||
|
||||
if (doc.title) {
|
||||
document.title = doc.title;
|
||||
}
|
||||
|
||||
["data-theme", "data-accent", "lang"].forEach(function (name) {
|
||||
var value = doc.documentElement.getAttribute(name);
|
||||
|
||||
if (value == null) {
|
||||
document.documentElement.removeAttribute(name);
|
||||
} else {
|
||||
document.documentElement.setAttribute(name, value);
|
||||
}
|
||||
});
|
||||
|
||||
var from = document.getElementById("app");
|
||||
var to = doc.getElementById("app");
|
||||
if (from && to) morph(from, to);
|
||||
|
||||
if (from && to) {
|
||||
morph(from, to);
|
||||
}
|
||||
|
||||
swapCss("html");
|
||||
// Components are re-rendered server-side into the new HTML; re-hydrate
|
||||
// their reactive scopes (and any browser-side API fetches) in place.
|
||||
if (window.__wrnexusHydrateScopes) window.__wrnexusHydrateScopes(document);
|
||||
if (window.__wrnexusHydrateCsrFetches) window.__wrnexusHydrateCsrFetches(document);
|
||||
window.dispatchEvent(new CustomEvent("wrnexus:hmr", { detail: { type: "html" } }));
|
||||
|
||||
if (window.__wrnexusHydrateScopes) {
|
||||
window.__wrnexusHydrateScopes(document);
|
||||
}
|
||||
|
||||
if (window.__wrnexusHydrateCsrFetches) {
|
||||
window.__wrnexusHydrateCsrFetches(document);
|
||||
}
|
||||
}
|
||||
|
||||
// Minimal index-based DOM morph: preserve matching nodes (keeps state/focus),
|
||||
@@ -1324,7 +1347,18 @@ export function createHandlers(deps: RuntimeDeps): Handlers {
|
||||
|
||||
// <html> attributes: no-flash theme (from cookie, validated) + active lang.
|
||||
const attrs: string[] = [];
|
||||
if (deps.theme) attrs.push(`data-theme="${resolvedTheme}"`);
|
||||
|
||||
if (deps.theme) {
|
||||
const themeName = resolveThemeName(ctx.cookies.get(THEME_COOKIE), deps.theme);
|
||||
|
||||
attrs.push(`data-theme="${themeName}"`);
|
||||
|
||||
const accentName = resolveAccentName(ctx.cookies.get(ACCENT_COOKIE), deps.theme);
|
||||
|
||||
if (accentName) {
|
||||
attrs.push(`data-accent="${accentName}"`);
|
||||
}
|
||||
}
|
||||
attrs.push(`lang="${safeLanguageTag(language)}"`);
|
||||
const htmlAttrs = attrs.length ? ` ${attrs.join(" ")}` : undefined;
|
||||
|
||||
@@ -1699,7 +1733,10 @@ export function collectScripts(
|
||||
scripts.push("/__wrnexus/reactive.js");
|
||||
}
|
||||
// The theme runtime is only needed when the page can switch themes.
|
||||
if (/\bdata-wire-theme-(toggle|set)\b/.test(body)) {
|
||||
if (
|
||||
/\bdata-wire-theme-(toggle|set)\b/.test(body) ||
|
||||
/\bdata-wire-accent-(set|clear)\b/.test(body)
|
||||
) {
|
||||
scripts.push(THEME_JS_HREF);
|
||||
}
|
||||
// Validation: schema descriptors + the generic validator, only for pages with a form.
|
||||
|
||||
Reference in New Issue
Block a user