![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
sanity-diff-patch
Advanced tools
Generates a set of Sanity patches needed to change an item (usually a document) from one shape to another
Generates a set of Sanity patches needed to change an item (usually a document) from one shape to another.
Most values will become simple set
, unset
or insert
operations, but it will also (by default) try to use diff-match-patch for strings (read more).
An ifRevisionID
constraint can be given to generate patches that include this revision as a safeguard, to prevent modifying documents that has changed since the diff was generated.
The document ID used in the patches is either extracted from item A and item B (_id
property), or can be set explicitly by using the id
option. This is required if the _id
property differs in the two items, to prevent patching the wrong document.
If encountering undefined
values within an array, they will be converted to null
values and print a warning to the console. Should you want to remove undefined values from arrays, manually remove them from the array prior to diffing (array.filter(item => typeof item === 'undefined')
is your friend).
npm install --save sanity-diff-patch
import {diffPatch} from 'sanity-diff-patch'
const patch = diffPatch(itemA, itemB)
/*
[
{patch: {id: 'docId', set: {...}}},
{patch: {id: 'docId', unset: [...]}},
{patch: {id: 'docId', insert: {...}}}
]
*/
import {diffPatch} from 'sanity-diff-patch'
import sanityClient from './myConfiguredSanityClient'
const itemA = {
_id: 'die-hard-iii',
_type: 'movie',
_rev: 'k0k0s',
name: 'Die Hard 3',
year: 1995,
characters: [
{
_key: 'ma4sg31',
name: 'John McClane'
},
{
_key: 'l13ma92',
name: 'Simon Gruber'
}
]
}
const itemB = {
_id: 'drafts.die-hard-iii',
_type: 'movie',
name: 'Die Hard with a Vengeance',
characters: [
{
_key: 'ma4sg31',
name: 'John McClane'
},
{
_key: 'l13ma92',
name: 'Simon Grüber'
}
]
}
// Specify id if the two documents do not match
const operations = diffPatch(itemA, itemB, {id: itemA._id, ifRevisionID: itemA._rev})
await sanityClient.transaction(operations).commit()
// Patches generated:
const generatedPatches = [
{
patch: {
id: 'die-hard-iii',
ifRevisionID: 'k0k0s',
set: {
'name': 'Die Hard with a Vengeance',
'characters[_key=="l13ma92"].name': 'Simon Grüber'
},
}
},
{
patch: {
id: 'die-hard-iii',
unset: ['year']
}
}
}
When encountering two strings to compare, this module will (by default) attempt to use diff-match-patch (DMP) to transition the string from one state to the next.
While these patches are extremely helpful (especially in a real-time, collaborative environment), they sometimes grow quite large and can be hard for humans to read. There are a few options you can use to tweak when this module will use these patches, and when to fall back to a regular set
-patch instead.
The default rules says:
To tune these rules, you can pass options to the differ:
import {diffPatch} from 'sanity-diff-patch'
diffPatch(itemA, itemB, {
diffMatchPatch: {
// Default is true, set to false to _always_ use `set`-patches
enabled: true,
// Only use diff-match-patch if target string is longer than this threshold
lengthThresholdAbsolute: 30,
// Only use generated diff-match-patch if the patch length is less than or equal to
// (targetString * relative). Example: A 100 character target with a relative factor
// of 1.2 will allow a 120 character diff-match-patch. If larger than this number,
// it will fall back to a regular `set` patch.
lengthThresholdRelative: 1.2
}
})
In addition to these rules, there are certain cases where it will never use diff-match-patch:
_type
, _key
, _ref
)MIT-licensed. See LICENSE.
FAQs
Generates a set of Sanity patches needed to change an item (usually a document) from one shape to another
The npm package sanity-diff-patch receives a total of 0 weekly downloads. As such, sanity-diff-patch popularity was classified as not popular.
We found that sanity-diff-patch demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.