fix: make useEditorState run before layout

This commit is contained in:
Nick the Sick 2024-11-11 13:33:14 +01:00
parent 05e1755d10
commit e6ce7b621d
No known key found for this signature in database
GPG Key ID: F575992F156E5BCC
2 changed files with 5 additions and 5 deletions

View File

@ -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('<p>Mistake</p>')
}, 0)
editor.commands.setContent('<p>Mistake</p>')
})
})

View File

@ -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<TEditor extends Editor | null = Editor | null> = {
@ -164,7 +166,7 @@ export function useEditorState<TSelectorResult>(
options.equalityFn ?? deepEqual,
)
useEffect(() => {
useLayoutEffect(() => {
return editorStateManager.watch(options.editor)
}, [options.editor, editorStateManager])