Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/plugins/sync-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,24 @@ export const ySyncPlugin = (yXmlFragment, {
}
onFirstRender()
return {
update: () => {
update: (view, prevState) => {
const pluginState = plugin.getState(view.state)
if (
pluginState.snapshot == null && pluginState.prevSnapshot == null
) {
// Check if document actually changed to skip unnecessary syncs from focus/selection changes
const docChanged = !prevState || !view.state.doc.eq(prevState.doc)

if (
// If the content doesn't change initially, we don't render anything to Yjs
// If the content was cleared by a user action, we want to catch the change and
// represent it in Yjs
initialContentChanged ||
view.state.doc.content.findDiffStart(
view.state.doc.type.createAndFill().content
) !== null
docChanged && (
// If the content doesn't change initially, we don't render anything to Yjs
// If the content was cleared by a user action, we want to catch the change and
// represent it in Yjs
initialContentChanged ||
view.state.doc.content.findDiffStart(
view.state.doc.type.createAndFill().content
) !== null
)
) {
initialContentChanged = true
if (
Expand Down