From ceb0eef944f2f867cb2dba04adfb6b028cf8c228 Mon Sep 17 00:00:00 2001 From: Maik Jablonski Date: Thu, 11 Aug 2022 18:04:10 +0200 Subject: [PATCH] Use passive listeners in prefetch (#4207) * Use passive listeners in prefetch Without passive=true, Lighthouse complains about not using passive listeners to improve scrolling performance. * Create cold-shoes-drum.md Co-authored-by: Nate Moore --- .changeset/cold-shoes-drum.md | 5 +++++ packages/integrations/prefetch/src/client.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/cold-shoes-drum.md diff --git a/.changeset/cold-shoes-drum.md b/.changeset/cold-shoes-drum.md new file mode 100644 index 000000000..b087ebc99 --- /dev/null +++ b/.changeset/cold-shoes-drum.md @@ -0,0 +1,5 @@ +--- +"@astrojs/prefetch": patch +--- + +Use `passive` event listeners for performance diff --git a/packages/integrations/prefetch/src/client.ts b/packages/integrations/prefetch/src/client.ts index 02661bb9d..187c808cb 100644 --- a/packages/integrations/prefetch/src/client.ts +++ b/packages/integrations/prefetch/src/client.ts @@ -25,7 +25,7 @@ let observer: IntersectionObserver; function observe(link: HTMLAnchorElement) { preloaded.add(link.href); observer.observe(link); - events.map((event) => link.addEventListener(event, onLinkEvent, { once: true })); + events.map((event) => link.addEventListener(event, onLinkEvent, { passive:true, once: true })); } function unobserve(link: HTMLAnchorElement) {