Skip to content

Commit

Permalink
fix(react): useIsomorphicLayoutEffect instead to support SSR #5872
Browse files Browse the repository at this point in the history
  • Loading branch information
nperez0111 committed Nov 26, 2024
1 parent 79e6f16 commit 5d7573b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/react/src/useEditorState.ts
Original file line number Diff line number Diff line change
@@ -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<TEditor extends Editor | null = Editor | null> = {
editor: TEditor;
transactionNumber: number;
Expand Down Expand Up @@ -164,7 +168,7 @@ export function useEditorState<TSelectorResult>(
options.equalityFn ?? deepEqual,
)

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

Expand Down

0 comments on commit 5d7573b

Please sign in to comment.