fix(csr): preserve translations across navigation
This commit is contained in:
@@ -161,6 +161,36 @@ test("synchronizes and rebinds i18n data during client navigation", async () =>
|
||||
expect(boundRoot).toBe(win.document.getElementById("app"));
|
||||
});
|
||||
|
||||
test("preserves same-language translations when an incoming navigation catalog is partial", async () => {
|
||||
install(`<div id="app"><a href="/about" id="lnk">About</a></div>`);
|
||||
win.__wrnI18n = {
|
||||
lang: "en",
|
||||
messages: { navigation: { home: "Home" }, footer: { contact: "Contact" } },
|
||||
fallbackMessages: {},
|
||||
};
|
||||
win.__wrnLang = {
|
||||
bind: (root: ParentNode) => {
|
||||
root.querySelectorAll("[data-t]").forEach((node) => {
|
||||
const parts = String(node.getAttribute("data-t") || "").split(".");
|
||||
let value: any = win.__wrnI18n.messages;
|
||||
for (const part of parts) value = value?.[part];
|
||||
node.textContent = typeof value === "string" ? value : node.getAttribute("data-t");
|
||||
});
|
||||
},
|
||||
};
|
||||
nextHtml =
|
||||
`<html lang="en"><body><div id="app"><p data-t="navigation.home">navigation.home</p></div>` +
|
||||
`<script>window.__wrnI18n={"lang":"en","messages":{},"fallbackMessages":{}};</script>` +
|
||||
`</body></html>`;
|
||||
|
||||
win.document.getElementById("lnk").click();
|
||||
await flush();
|
||||
|
||||
expect(win.__wrnI18n.messages.navigation.home).toBe("Home");
|
||||
expect(win.__wrnI18n.messages.footer.contact).toBe("Contact");
|
||||
expect(win.document.querySelector("[data-t]")?.textContent).toBe("Home");
|
||||
});
|
||||
|
||||
test("unmounts and remounts package runtimes during client navigation", async () => {
|
||||
install(
|
||||
`<div id="app"><div data-wrnexus-runtime="captcha">Old</div><a href="/next" id="lnk">Next</a></div>`,
|
||||
|
||||
Reference in New Issue
Block a user