Skip to content

Commit

Permalink
[form-builder] Fix invalid unset patch (#1515)
Browse files Browse the repository at this point in the history
* [form-builder] Fix path debug output

* [form-builder] Block editor: don't send unset patch if the data is a placeholder
  • Loading branch information
skogsmaskin committed Oct 2, 2019
1 parent 7d7a268 commit a976ded
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,12 @@ export default function createOperationToPatches(

function removeNodePatch(operation: Operation, beforeValue: SlateValue, afterValue: SlateValue) {
const patches = []
const isPlaceholder = beforeValue.document.nodes
.get(operation.path.get(0))
.data.get('placeholder')
const block = toBlock(beforeValue, operation.path.get(0))
if (operation.path.size === 1) {
// Send unset patch unless is it is a placeholder
if (operation.path.size === 1 && !isPlaceholder) {
patches.push(unset([{_key: block._key}]))
}
if (operation.path.size > 1) {
Expand Down
4 changes: 3 additions & 1 deletion packages/@sanity/form-builder/src/patch/primitive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export default function apply(value, patch) {
throw new Error(
`Cannot apply deep operations on primitive values. Received patch with type "${
patch.type
}" and path "${patch.path.join('.')} that targeted the value "${JSON.stringify(value)}"`
}" and path "${patch.path
.map(path => JSON.stringify(path))
.join('.')} that targeted the value "${JSON.stringify(value)}"`
)
}

Expand Down

0 comments on commit a976ded

Please sign in to comment.