Skip to content

Commit

Permalink
Use passive listeners in prefetch (#4207)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
jablonski and natemoo-re authored Aug 11, 2022
1 parent 54ff0a4 commit ceb0eef
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/cold-shoes-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/prefetch": patch
---

Use `passive` event listeners for performance
2 changes: 1 addition & 1 deletion packages/integrations/prefetch/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit ceb0eef

Please sign in to comment.