Skip to content

Commit

Permalink
fix ssr prop mismatch (ianstormtaylor#4682)
Browse files Browse the repository at this point in the history
* fix ssr prop mismatch

* added changeset
  • Loading branch information
matthewkeil authored Nov 22, 2021
1 parent 2523dc4 commit e538065
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
12 changes: 12 additions & 0 deletions .changeset/strong-jeans-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'slate-react': minor
---

Support SSR for autoCorrect, spellCheck and autoCapitalize.
Fixes prop mismatch between server and client.
Removes the need to add
<Editable
spellCheck={false}
autoCorrect="false"
autoCapitalize="false"
/>
18 changes: 15 additions & 3 deletions packages/slate-react/src/components/editable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
IS_FIREFOX_LEGACY,
IS_QQBROWSER,
IS_SAFARI,
CAN_USE_DOM,
} from '../utils/environment'
import { ReactEditor } from '..'
import { ReadOnlyContext } from '../hooks/use-read-only'
Expand Down Expand Up @@ -579,12 +580,23 @@ export const Editable = (props: EditableProps) => {
{...attributes}
// COMPAT: Certain browsers don't support the `beforeinput` event, so we'd
// have to use hacks to make these replacement-based features work.
spellCheck={!HAS_BEFORE_INPUT_SUPPORT ? false : attributes.spellCheck}
// For SSR situations HAS_BEFORE_INPUT_SUPPORT is false and results in prop
// mismatch warning app moves to browser. Pass-through consumer props when
// not CAN_USE_DOM (SSR) and default to falsy value
spellCheck={
HAS_BEFORE_INPUT_SUPPORT || !CAN_USE_DOM
? attributes.spellCheck
: false
}
autoCorrect={
!HAS_BEFORE_INPUT_SUPPORT ? 'false' : attributes.autoCorrect
HAS_BEFORE_INPUT_SUPPORT || !CAN_USE_DOM
? attributes.autoCorrect
: 'false'
}
autoCapitalize={
!HAS_BEFORE_INPUT_SUPPORT ? 'false' : attributes.autoCapitalize
HAS_BEFORE_INPUT_SUPPORT || !CAN_USE_DOM
? attributes.autoCapitalize
: 'false'
}
data-slate-editor
data-slate-node="value"
Expand Down

0 comments on commit e538065

Please sign in to comment.