Skip to content

Commit

Permalink
fix: make useEditorState run before layout
Browse files Browse the repository at this point in the history
  • Loading branch information
nperez0111 committed Nov 11, 2024
1 parent 05e1755 commit e6ce7b6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 1 addition & 3 deletions demos/src/Extensions/History/React/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>')
})
})

Expand Down
6 changes: 4 additions & 2 deletions packages/react/src/useEditorState.ts
Original file line number Diff line number Diff line change
@@ -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> = {
Expand Down Expand Up @@ -164,7 +166,7 @@ export function useEditorState<TSelectorResult>(
options.equalityFn ?? deepEqual,
)

useEffect(() => {
useLayoutEffect(() => {
return editorStateManager.watch(options.editor)
}, [options.editor, editorStateManager])

Expand Down

0 comments on commit e6ce7b6

Please sign in to comment.