Skip to content

Commit

Permalink
Add a guard against potentially missing documents.fonts (#370)
Browse files Browse the repository at this point in the history
* Handle document.fonts not being define

fixes #368

* Update .changeset/great-moose-judge.md

---------

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
  • Loading branch information
ArnaudRinquin and Andarist committed Jun 21, 2023
1 parent 05b014a commit d33b120
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/great-moose-judge.md
@@ -0,0 +1,5 @@
---
'react-textarea-autosize': patch
---

Add a guard against potentially missing `documents.fonts`
5 changes: 5 additions & 0 deletions src/hooks.ts
Expand Up @@ -36,6 +36,11 @@ function useListener<
React.useLayoutEffect(() => {
const handler: typeof listener = (ev) => latestListener.current(ev);

// might happen if document.fonts is not defined, for instance
if (!target) {
return;
}

target.addEventListener(type, handler);
return () => target.removeEventListener(type, handler);
}, []);
Expand Down

0 comments on commit d33b120

Please sign in to comment.