@@ -172,6 +172,33 @@ const UniqueID = Extension.create({
172
172
? void 0
173
173
: _a . attrs [ attributeName ] ;
174
174
if ( id === null ) {
175
+ // edge case, when using collaboration, yjs will set the id to null in `_forceRerender`
176
+ // when loading the editor
177
+ // this checks for this case and keeps it at initialBlockId so there will be no change
178
+ const initialDoc = oldState . doc . type . createAndFill ( ) ! . content ;
179
+ const wasInitial =
180
+ oldState . doc . content . findDiffStart ( initialDoc ) === null ;
181
+
182
+ if ( wasInitial ) {
183
+ // the old state was the "initial content"
184
+ const jsonNode = JSON . parse (
185
+ JSON . stringify ( newState . doc . toJSON ( ) )
186
+ ) ;
187
+ jsonNode . content [ 0 ] . content [ 0 ] . attrs . id = "initialBlockId" ;
188
+ // would the new state with the fix also be the "initial content"?
189
+ if (
190
+ JSON . stringify ( jsonNode . content ) ===
191
+ JSON . stringify ( initialDoc . toJSON ( ) )
192
+ ) {
193
+ // yes, apply the fix
194
+ tr . setNodeMarkup ( pos , undefined , {
195
+ ...node . attrs ,
196
+ [ attributeName ] : "initialBlockId" ,
197
+ } ) ;
198
+ return ;
199
+ }
200
+ }
201
+
175
202
tr . setNodeMarkup ( pos , undefined , {
176
203
...node . attrs ,
177
204
[ attributeName ] : generateID ( ) ,
@@ -285,5 +312,5 @@ const UniqueID = Extension.create({
285
312
} ,
286
313
} ) ;
287
314
288
- export { UniqueID , UniqueID as default } ;
315
+ export { UniqueID as default , UniqueID } ;
289
316
//# sourceMappingURL=tiptap-extension-unique-id.esm.js.map
0 commit comments