From bbe22d284a39c05cd15a35a61931812fbe365a0a Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Fri, 27 Sep 2024 00:06:30 +0200 Subject: [PATCH 1/2] ensure `Element` is available before polyfilling --- packages/@headlessui-react/src/hooks/use-transition.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/@headlessui-react/src/hooks/use-transition.ts b/packages/@headlessui-react/src/hooks/use-transition.ts index bb7bec4c7b..686839d344 100644 --- a/packages/@headlessui-react/src/hooks/use-transition.ts +++ b/packages/@headlessui-react/src/hooks/use-transition.ts @@ -7,12 +7,13 @@ import { useIsoMorphicEffect } from './use-iso-morphic-effect' if ( typeof process !== 'undefined' && typeof globalThis !== 'undefined' && + typeof Element !== 'undefined' && // Strange string concatenation is on purpose to prevent `esbuild` from // replacing `process.env.NODE_ENV` with `production` in the build output, // eliminating this whole branch. process?.env?.['NODE' + '_' + 'ENV'] === 'test' ) { - if (typeof Element.prototype.getAnimations === 'undefined') { + if (typeof Element?.prototype?.getAnimations === 'undefined') { Element.prototype.getAnimations = function getAnimationsPolyfill() { console.warn( [ From 9cd8d0837edc066c9225f6f02f5bf31d7d2aba91 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Fri, 27 Sep 2024 00:09:15 +0200 Subject: [PATCH 2/2] update changelog --- packages/@headlessui-react/CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/@headlessui-react/CHANGELOG.md b/packages/@headlessui-react/CHANGELOG.md index f750900bfe..f2a1259258 100644 --- a/packages/@headlessui-react/CHANGELOG.md +++ b/packages/@headlessui-react/CHANGELOG.md @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -- Nothing yet! +### Fixed + +- Ensure `Element` is available before polyfilling to prevent crashes in non-browser environments ([#3493](https://github.com/tailwindlabs/headlessui/pull/3493)) ## [2.1.8] - 2024-09-12