Skip to content

Commit

Permalink
Handle document.fonts not being define
Browse files Browse the repository at this point in the history
fixes #368
  • Loading branch information
ArnaudRinquin committed Apr 14, 2023
1 parent ab4c1ec commit 2325064
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-textarea-autosize': patch
---

Clean handling of absence of document.fonts API
5 changes: 5 additions & 0 deletions src/hooks.ts
Original file line number Diff line number Diff line change
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 2325064

Please sign in to comment.