Skip to content

Commit f2c80c4

Browse files
authored
Ensure Element is available before polyfilling (#3493)
In some environments `Element` won't be available, which is needed for the `Element.prototype.getAnimations` polyfill. If `Element` is not available at all, it means that we are not in a browser so we don't need the polyfill. Fixes: #3490
1 parent 5ca68a9 commit f2c80c4

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

packages/@headlessui-react/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
- Nothing yet!
10+
### Fixed
11+
12+
- Ensure `Element` is available before polyfilling to prevent crashes in non-browser environments ([#3493](https://github.com/tailwindlabs/headlessui/pull/3493))
1113

1214
## [2.1.8] - 2024-09-12
1315

packages/@headlessui-react/src/hooks/use-transition.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ import { useIsoMorphicEffect } from './use-iso-morphic-effect'
77
if (
88
typeof process !== 'undefined' &&
99
typeof globalThis !== 'undefined' &&
10+
typeof Element !== 'undefined' &&
1011
// Strange string concatenation is on purpose to prevent `esbuild` from
1112
// replacing `process.env.NODE_ENV` with `production` in the build output,
1213
// eliminating this whole branch.
1314
process?.env?.['NODE' + '_' + 'ENV'] === 'test'
1415
) {
15-
if (typeof Element.prototype.getAnimations === 'undefined') {
16+
if (typeof Element?.prototype?.getAnimations === 'undefined') {
1617
Element.prototype.getAnimations = function getAnimationsPolyfill() {
1718
console.warn(
1819
[

0 commit comments

Comments
 (0)