diff --git a/.changeset/great-moose-judge.md b/.changeset/great-moose-judge.md new file mode 100644 index 00000000..baf30b28 --- /dev/null +++ b/.changeset/great-moose-judge.md @@ -0,0 +1,5 @@ +--- +'react-textarea-autosize': patch +--- + +Clean handling of absence of document.fonts API diff --git a/src/hooks.ts b/src/hooks.ts index 6bf57841..98296459 100644 --- a/src/hooks.ts +++ b/src/hooks.ts @@ -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); }, []);