fix(csr): consume hydration metadata from live DOM
This commit is contained in:
@@ -522,6 +522,33 @@ test("template literals work inside browser API call arguments", () => {
|
||||
expect(win.document.querySelector("button")!.textContent).toBe("Saved 3");
|
||||
});
|
||||
|
||||
test("hydration consumes private scope, behavior, and binding metadata", () => {
|
||||
const behavior = Buffer.from(
|
||||
JSON.stringify({
|
||||
functions: "function toggle() { active = !active }",
|
||||
watches: [],
|
||||
lifecycle: {},
|
||||
}),
|
||||
).toString("base64");
|
||||
const scope = Buffer.from(JSON.stringify({ active: false })).toString("base64");
|
||||
const win = mount(
|
||||
`<div id="scope" data-scope="active: false" data-wrn-scope="${scope}" data-wrn-behavior="${behavior}">` +
|
||||
`<button id="toggle" data-wrn-bind-0='["aria-expanded","{active}"]' data-on-click="toggle()">Toggle</button>` +
|
||||
`</div>`,
|
||||
);
|
||||
const root = win.document.getElementById("scope")!;
|
||||
const button = win.document.getElementById("toggle")!;
|
||||
|
||||
expect(root.hasAttribute("data-scope")).toBe(false);
|
||||
expect(root.hasAttribute("data-wrn-scope")).toBe(false);
|
||||
expect(root.hasAttribute("data-wrn-behavior")).toBe(false);
|
||||
expect(button.hasAttribute("data-wrn-bind-0")).toBe(false);
|
||||
expect(button.getAttribute("aria-expanded")).toBe("false");
|
||||
|
||||
(button as unknown as { click(): void }).click();
|
||||
expect(button.getAttribute("aria-expanded")).toBe("true");
|
||||
});
|
||||
|
||||
test("compiled client functions are not overwritten by fallback behavior parsing", () => {
|
||||
const behavior = Buffer.from(
|
||||
JSON.stringify({
|
||||
@@ -817,8 +844,7 @@ test("development runtime accepts component-local and inline wire variables", ()
|
||||
win.document.head.innerHTML =
|
||||
`<style>.component { --wire-component-local: red; color: var(--wire-component-local); ` +
|
||||
`background: var(--wire-inline-local); }</style>`;
|
||||
win.document.body.innerHTML =
|
||||
`<div class="component" style="--wire-inline-local: blue" data-scope=""></div>`;
|
||||
win.document.body.innerHTML = `<div class="component" style="--wire-inline-local: blue" data-scope=""></div>`;
|
||||
(globalThis as Record<string, unknown>).window = win;
|
||||
(globalThis as Record<string, unknown>).document = win.document;
|
||||
(globalThis as Record<string, unknown>).location = win.location;
|
||||
|
||||
Reference in New Issue
Block a user