WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 9d5aeb1

Browse files
authored
fix: prevent infinite loop between UniqueID and TrailingNode extensions (#7202)
This resolves an issue where using UniqueID and TrailingNode extensions together caused an infinite transaction loop, freezing browser tabs. The problem occurred because: 1. TrailingNode would insert a trailing node 2. UniqueID would add an ID to that node via setNodeMarkup 3. TrailingNode would see the document change and re-evaluate 4. This triggered another insertion, creating an infinite loop The fix introduces a transaction metadata flag (__uniqueIDTransaction) that UniqueID sets on its transactions. TrailingNode now checks for this flag and skips re-evaluation for UniqueID transactions, breaking the loop while preserving correct behavior for both extensions. Fixes #6870
1 parent 50e8905 commit 9d5aeb1

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@tiptap/extension-unique-id': patch
3+
'@tiptap/extension-trailing-node': patch
4+
---
5+
6+
Fixed infinite transaction loop that caused browser tabs to freeze when using UniqueID and TrailingNode extensions together.

packages/extension-unique-id/src/unique-id.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,13 @@ export const UniqueID = Extension.create<UniqueIDOptions>({
243243
}
244244

245245
// `tr.setNodeMarkup` resets the stored marks
246-
// so well restore them if they exist
246+
// so we'll restore them if they exist
247247
tr.setStoredMarks(newState.tr.storedMarks)
248248

249+
// Mark this transaction as coming from UniqueID
250+
// to prevent infinite loops with other extensions (e.g., TrailingNode)
251+
tr.setMeta('__uniqueIDTransaction', true)
252+
249253
return tr
250254
},
251255

packages/extensions/src/trailing-node/trailing-node.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ export const TrailingNode = Extension.create<TrailingNodeOptions>({
7676
return value
7777
}
7878

79+
// Ignore transactions from UniqueID extension to prevent infinite loops
80+
// when UniqueID adds IDs to newly inserted trailing nodes
81+
if (tr.getMeta('__uniqueIDTransaction')) {
82+
return value
83+
}
84+
7985
const lastNode = tr.doc.lastChild
8086

8187
return !nodeEqualsType({ node: lastNode, types: disabledNodes })

0 commit comments

Comments
 (0)