diff --git a/demos/src/Extensions/History/React/index.spec.js b/demos/src/Extensions/History/React/index.spec.js index beae110bfa..b358de7fbc 100644 --- a/demos/src/Extensions/History/React/index.spec.js +++ b/demos/src/Extensions/History/React/index.spec.js @@ -2,9 +2,7 @@ context('/src/Extensions/History/React/', () => { beforeEach(() => { cy.visit('/src/Extensions/History/React/') cy.get('.tiptap').then(([{ editor }]) => { - setTimeout(() => { - editor.commands.setContent('

Mistake

') - }, 0) + editor.commands.setContent('

Mistake

') }) }) diff --git a/packages/react/src/useEditorState.ts b/packages/react/src/useEditorState.ts index 26aabf0382..6eef6a7c40 100644 --- a/packages/react/src/useEditorState.ts +++ b/packages/react/src/useEditorState.ts @@ -1,6 +1,8 @@ import type { Editor } from '@tiptap/core' import deepEqual from 'fast-deep-equal/es6/react' -import { useDebugValue, useEffect, useState } from 'react' +import { + useDebugValue, useLayoutEffect, useState, +} from 'react' import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector' export type EditorStateSnapshot = { @@ -164,7 +166,7 @@ export function useEditorState( options.equalityFn ?? deepEqual, ) - useEffect(() => { + useLayoutEffect(() => { return editorStateManager.watch(options.editor) }, [options.editor, editorStateManager])