Skip to content

Commit

Permalink
replace IS_FIREFOX with IS_FIREFOX_LEGACY in HAS_BEFORE_INPUT_SUPPORT (
Browse files Browse the repository at this point in the history
…ianstormtaylor#4150)

* replace IS_FIREFOX with IS_FIREFOX_LEGACY in HAS_BEFORE_INPUT_SUPPORT

* fix linting errors

* Create afraid-donuts-flow.md

* Update environment.ts

Co-authored-by: Ian Storm Taylor <ian@ianstormtaylor.com>
# Conflicts:
#	packages/slate-react/src/utils/environment.ts
  • Loading branch information
nivekithan authored and ulion committed May 22, 2021
1 parent c2fefd2 commit 748e47a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/slate-react/src/components/editable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
IS_SAFARI,
IS_EDGE_LEGACY,
IS_CHROME_LEGACY,
IS_FIREFOX_LEGACY,
} from '../utils/environment'
import { ReactEditor } from '..'
import { ReadOnlyContext } from '../hooks/use-read-only'
Expand Down Expand Up @@ -49,7 +50,7 @@ import {
// COMPAT: Firefox/Edge Legacy don't support the `beforeinput` event
// Chrome Legacy doesn't support `beforeinput` correctly
const HAS_BEFORE_INPUT_SUPPORT = !(
IS_FIREFOX ||
IS_FIREFOX_LEGACY ||
IS_EDGE_LEGACY ||
IS_CHROME_LEGACY
)
Expand Down
21 changes: 20 additions & 1 deletion packages/slate-react/src/utils/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,26 @@ export const IS_EDGE_LEGACY =
typeof navigator !== 'undefined' &&
/Edge?\/(?:[0-6][0-9]|[0-7][0-8])/i.test(navigator.userAgent)

// Native beforeInput events don't work well with react on Chrome 75 and older, Chrome 76+ can use beforeInput
export const IS_CHROME =
typeof navigator !== 'undefined' && /Chrome/i.test(navigator.userAgent)

// Native `beforeInput` events don't work well with react on Chrome 75
// and older, Chrome 76+ can use `beforeInput` though.
export const IS_CHROME_LEGACY =
typeof navigator !== 'undefined' &&
/Chrome?\/(?:[0-7][0-5]|[0-6][0-9])/i.test(navigator.userAgent)

// Firefox did not support `beforeInput` until `v87`.
export const IS_FIREFOX_LEGACY =
typeof navigator !== 'undefined' &&
/^(?!.*Seamonkey)(?=.*Firefox\/(?:[0-7][0-9]|[0-8][0-6])).*/i.test(
navigator.userAgent
)

// Check if DOM is available as React does internally.
// 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'
)

0 comments on commit 748e47a

Please sign in to comment.