release: WRNexusJS 0.8.2
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@wrnexus/csr",
|
||||
"version": "0.8.1",
|
||||
"version": "0.8.2",
|
||||
"type": "module",
|
||||
"main": "src/index.ts",
|
||||
"exports": {
|
||||
|
||||
@@ -638,7 +638,10 @@ export const NAV_RUNTIME = String.raw`
|
||||
while (prefetched.size > 20) prefetched.delete(prefetched.keys().next().value);
|
||||
}
|
||||
|
||||
document.addEventListener("pointerover", function (event) {
|
||||
// Prefetch only on explicit pointer intent. Delegated pointerover fires when
|
||||
// scrolling moves links underneath a stationary pointer, which can otherwise
|
||||
// download every link on a long index page.
|
||||
document.addEventListener("pointerdown", function (event) {
|
||||
var anchor = event.target && event.target.closest ? event.target.closest("a") : null;
|
||||
prefetch(anchor);
|
||||
}, { passive: true });
|
||||
|
||||
@@ -82,6 +82,18 @@ test("prefetches focused routes once and reuses the document during navigation",
|
||||
expect(win.document.querySelector("h1")?.textContent).toBe("Prefetched");
|
||||
});
|
||||
|
||||
test("does not prefetch links merely passing under the pointer while scrolling", async () => {
|
||||
install(`<div id="app"><a href="/about" id="prefetch">About</a></div>`);
|
||||
const link = win.document.getElementById("prefetch");
|
||||
link.dispatchEvent(new win.PointerEvent("pointerover", { bubbles: true }));
|
||||
await flush();
|
||||
expect(fetchCalls).toHaveLength(0);
|
||||
link.dispatchEvent(new win.PointerEvent("pointerdown", { bubbles: true }));
|
||||
await flush();
|
||||
expect(fetchCalls).toHaveLength(1);
|
||||
expect(fetchCalls[0]?.opts.headers["x-wrnexus-prefetch"]).toBe("1");
|
||||
});
|
||||
|
||||
test("ignores cross-origin links (full navigation)", async () => {
|
||||
install(`<div id="app"><a href="https://other.test/x" id="lnk">x</a></div>`);
|
||||
win.document.getElementById("lnk").click();
|
||||
|
||||
Reference in New Issue
Block a user