fix: use editorView for isDestroyed check for SSR (#6233)

* fix: use `editorView` for `isDestroyed` check for SSR

* chore: update import of `fast-deep-equal` to include extension

* chore: fix unrelated issue

* chore: add changeset

---------

Co-authored-by: bdbch <6538827+bdbch@users.noreply.github.com>
This commit is contained in:
Nick Perez 2025-04-23 15:15:06 +02:00 committed by GitHub
parent dca2852f25
commit 5e957e5373
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 9 additions and 5 deletions

View File

@ -0,0 +1,5 @@
---
'@tiptap/core': major
---
This resolves in issue with SSR where the isDestroyed property could not be read while in SSR

View File

@ -1,6 +1,5 @@
import { Extension } from '@tiptap/core'
import { NodeSelection, Plugin } from '@tiptap/pm/state'
import { EditorView } from '@tiptap/pm/view'
function removeNode(node) {
node.parentNode.removeChild(node)
@ -63,7 +62,7 @@ export default Extension.create({
// from: view.nodeDOM(view.state.selection.from),
// to: view.nodeDOM(view.state.selection.to),
// })
const { dom, text } = EditorView.serializeForClipboard(view, slice)
const { dom, text } = view.serializeForClipboard(slice)
e.dataTransfer.clearData()
e.dataTransfer.setData('text/html', dom.innerHTML)

View File

@ -287,6 +287,7 @@ export class Editor extends EventEmitter<EditorEvents> {
composing: false,
dragging: null,
editable: true,
isDestroyed: false,
} as EditorView,
{
get: (obj, key) => {
@ -717,8 +718,7 @@ export class Editor extends EventEmitter<EditorEvents> {
* Check if the editor is already destroyed.
*/
public get isDestroyed(): boolean {
// @ts-ignore
return !this.view?.docView
return !this.editorView?.isDestroyed
}
public $node(selector: string, attributes?: { [key: string]: any }): NodePos | null {

View File

@ -1,5 +1,5 @@
import type { Editor } from '@tiptap/core'
import deepEqual from 'fast-deep-equal/es6/react'
import deepEqual from 'fast-deep-equal/es6/react.js'
import { useDebugValue, useEffect, useLayoutEffect, useState } from 'react'
import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'