mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-10 17:24:02 +02: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:
@@ -1,7 +1,9 @@
|
|||||||
import { useLayoutEffect, useEffect } from 'react'
|
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 =
|
export const useIsomorphicLayoutEffect = CAN_USE_DOM
|
||||||
typeof window !== 'undefined' ? useLayoutEffect : useEffect
|
? useLayoutEffect
|
||||||
|
: useEffect
|
||||||
|
@@ -27,3 +27,13 @@ export const IS_CHROME =
|
|||||||
export const IS_CHROME_LEGACY =
|
export const IS_CHROME_LEGACY =
|
||||||
typeof navigator !== 'undefined' &&
|
typeof navigator !== 'undefined' &&
|
||||||
/Chrome?\/(?:[0-7][0-5]|[0-6][0-9])/i.test(navigator.userAgent)
|
/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'
|
||||||
|
)
|
||||||
|
Reference in New Issue
Block a user