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 06facb6

Browse files
authored
fix: prevent ProseMirror document mutation during server-side rendering (#7296)
1 parent 7c72d24 commit 06facb6

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@tiptap/extension-table-of-contents": patch
3+
---
4+
5+
Fixed a bug that mutated the ProseMirror document during server-side rendering, which could cause "Invalid content for node doc" errors.

packages/extension-table-of-contents/src/plugin.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ export const TableOfContentsPlugin = ({
1313
key: new PluginKey('tableOfContent'),
1414

1515
appendTransaction(transactions, _oldState, newState) {
16+
// Avoid running on the server where `window` / DOM is not available.
17+
if (typeof window === 'undefined') {
18+
return null
19+
}
20+
1621
const tr = newState.tr
1722
let modified = false
1823

packages/extension-table-of-contents/src/tableOfContents.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,11 @@ export const TableOfContents = Extension.create<TableOfContentsOptions, TableOfC
262262
},
263263

264264
onCreate() {
265+
// Avoid mutating the document during server-side rendering.
266+
if (typeof window === 'undefined' || !this.editor.view) {
267+
return
268+
}
269+
265270
const { tr } = this.editor.state
266271
const existingIds: string[] = []
267272

0 commit comments

Comments
 (0)