mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-02-24 09:13:24 +01:00
Aligning DOM checking condition to what facebook/react does (#4114)
* feat: add Deno SSR support * fix: check if DOM available as React does Co-authored-by: oyzhen <oyzhen@vip.qq.com>
This commit is contained in:
parent
4dd8b98f7f
commit
efce5373fd
@ -1,7 +1,9 @@
|
||||
import { useLayoutEffect, useEffect } from 'react'
|
||||
import { CAN_USE_DOM } from '../utils/environment'
|
||||
|
||||
/**
|
||||
* Prevent warning on SSR by falling back to useEffect when window is not defined
|
||||
* Prevent warning on SSR by falling back to useEffect when DOM isn't available
|
||||
*/
|
||||
export const useIsomorphicLayoutEffect =
|
||||
typeof window !== 'undefined' ? useLayoutEffect : useEffect
|
||||
export const useIsomorphicLayoutEffect = CAN_USE_DOM
|
||||
? useLayoutEffect
|
||||
: useEffect
|
||||
|
@ -27,3 +27,13 @@ export const IS_CHROME =
|
||||
export const IS_CHROME_LEGACY =
|
||||
typeof navigator !== 'undefined' &&
|
||||
/Chrome?\/(?:[0-7][0-5]|[0-6][0-9])/i.test(navigator.userAgent)
|
||||
|
||||
/**
|
||||
* Check if DOM is available as React does internally.
|
||||
* @see https://github.com/facebook/react/blob/master/packages/shared/ExecutionEnvironment.js
|
||||
*/
|
||||
export const CAN_USE_DOM = !!(
|
||||
typeof window !== 'undefined' &&
|
||||
typeof window.document !== 'undefined' &&
|
||||
typeof window.document.createElement !== 'undefined'
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user