diff --git a/packages/react/src/useEditorState.ts b/packages/react/src/useEditorState.ts index c6292b768f..5da43e4474 100644 --- a/packages/react/src/useEditorState.ts +++ b/packages/react/src/useEditorState.ts @@ -1,8 +1,12 @@ import type { Editor } from '@tiptap/core' import deepEqual from 'fast-deep-equal/es6/react' -import { useDebugValue, useLayoutEffect, useState } from 'react' +import { + useDebugValue, useEffect, useLayoutEffect, useState, +} from 'react' import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector' +const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect + export type EditorStateSnapshot = { editor: TEditor; transactionNumber: number; @@ -164,7 +168,7 @@ export function useEditorState( options.equalityFn ?? deepEqual, ) - useLayoutEffect(() => { + useIsomorphicLayoutEffect(() => { return editorStateManager.watch(options.editor) }, [options.editor, editorStateManager])