Preserve inert control scripts during client navigation
This commit is contained in:
1 parent
41383960f8
commit
c3818f0041
4 files changed
+14
-4
No files matched your search
@@ -106,11 +106,18 @@ test("navigation supplies TrustedHTML to the document parser", async () => {
|
||||
|
||||
test("navigation replaces document control registries before hydration", async () => {
|
||||
install('<div id="app"><a href="/next" id="lnk">Next</a></div><script type="application/json" data-wrn-controls id="old">[]</script>');
|
||||
nextHtml = '<html><body><div id="app">Next</div><script type="application/json" data-wrn-controls id="new">[[{"cond":null,"body":"Ready"}]]</script></body></html>';
|
||||
const importNode = win.document.importNode.bind(win.document);
|
||||
win.document.importNode = (node: any, deep: boolean) => {
|
||||
if (node.nodeName === "SCRIPT") throw new Error("Script text must not be cloned under Trusted Types");
|
||||
return importNode(node, deep);
|
||||
};
|
||||
nextHtml = '<html><body><div id="app">Next</div><script type="application/json" data-wrn-controls id="new">[[{"cond":null,"body":"Ready"}]]</script><script data-wrn-controls id="executable">window.bad = true</script></body></html>';
|
||||
win.document.getElementById("lnk").click();
|
||||
await flush();
|
||||
expect(win.document.getElementById("old")).toBeNull();
|
||||
expect(win.document.getElementById("new")?.textContent).toContain("Ready");
|
||||
expect(win.document.getElementById("new")?.type).toBe("application/json");
|
||||
expect(win.document.getElementById("executable")).toBeNull();
|
||||
});
|
||||
|
||||
test("prefetches focused routes once and reuses the document during navigation", async () => {
|
||||
|
||||
Reference in new issue
Block a user