From f521fb7e3ea9cc7b6c02ec32b7329784b4d8e854 Mon Sep 17 00:00:00 2001 From: elrrrrrrr Date: Fri, 10 Jan 2025 18:56:21 +0800 Subject: [PATCH] fix: sever env detection for deno (#4064) --- src/_internal/utils/env.ts | 4 ++-- src/_internal/utils/helper.ts | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/_internal/utils/env.ts b/src/_internal/utils/env.ts index c112525c1f..a0369b5226 100644 --- a/src/_internal/utils/env.ts +++ b/src/_internal/utils/env.ts @@ -1,9 +1,9 @@ import React, { useEffect, useLayoutEffect } from 'react' -import { hasRequestAnimationFrame, isWindowDefined } from './helper' +import { hasRequestAnimationFrame, isLegacyDeno, isWindowDefined } from './helper' export const IS_REACT_LEGACY = !React.useId -export const IS_SERVER = !isWindowDefined || 'Deno' in globalThis +export const IS_SERVER = !isWindowDefined || isLegacyDeno // Polyfill requestAnimationFrame export const rAF = ( diff --git a/src/_internal/utils/helper.ts b/src/_internal/utils/helper.ts index e73a272db7..da3092f289 100644 --- a/src/_internal/utils/helper.ts +++ b/src/_internal/utils/helper.ts @@ -10,6 +10,8 @@ const STR_UNDEFINED = 'undefined' // NOTE: Use the function to guarantee it's re-evaluated between jsdom and node runtime for tests. export const isWindowDefined = typeof window != STR_UNDEFINED export const isDocumentDefined = typeof document != STR_UNDEFINED +export const isLegacyDeno = isWindowDefined && 'Deno' in window + export const hasRequestAnimationFrame = () => isWindowDefined && typeof window['requestAnimationFrame'] != STR_UNDEFINED