mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-24 03:39:01 +08:00
fix(react): useLayoutEffect instead of useEffect to cut down on reflow (#5825)
Some checks failed
build / lint (20) (push) Has been cancelled
build / test (20, map[name:Demos/Examples spec:./demos/src/Examples/**/*.spec.{js,ts}]) (push) Has been cancelled
build / test (20, map[name:Demos/Experiments spec:./demos/src/Experiments/**/*.spec.{js,ts}]) (push) Has been cancelled
build / test (20, map[name:Demos/Extensions spec:./demos/src/Extensions/**/*.spec.{js,ts}]) (push) Has been cancelled
build / test (20, map[name:Demos/GuideContent spec:./demos/src/GuideContent/**/*.spec.{js,ts}]) (push) Has been cancelled
build / test (20, map[name:Demos/GuideGettingStarted spec:./demos/src/GuideGettingStarted/**/*.spec.{js,ts}]) (push) Has been cancelled
build / test (20, map[name:Demos/Marks spec:./demos/src/Marks/**/*.spec.{js,ts}]) (push) Has been cancelled
build / test (20, map[name:Demos/Nodes spec:./demos/src/Nodes/**/*.spec.{js,ts}]) (push) Has been cancelled
build / test (20, map[name:Integration spec:./tests/cypress/integration/**/*.spec.{js,ts}]) (push) Has been cancelled
Publish / Release (20) (push) Has been cancelled
build / build (20) (push) Has been cancelled
Some checks failed
build / lint (20) (push) Has been cancelled
build / test (20, map[name:Demos/Examples spec:./demos/src/Examples/**/*.spec.{js,ts}]) (push) Has been cancelled
build / test (20, map[name:Demos/Experiments spec:./demos/src/Experiments/**/*.spec.{js,ts}]) (push) Has been cancelled
build / test (20, map[name:Demos/Extensions spec:./demos/src/Extensions/**/*.spec.{js,ts}]) (push) Has been cancelled
build / test (20, map[name:Demos/GuideContent spec:./demos/src/GuideContent/**/*.spec.{js,ts}]) (push) Has been cancelled
build / test (20, map[name:Demos/GuideGettingStarted spec:./demos/src/GuideGettingStarted/**/*.spec.{js,ts}]) (push) Has been cancelled
build / test (20, map[name:Demos/Marks spec:./demos/src/Marks/**/*.spec.{js,ts}]) (push) Has been cancelled
build / test (20, map[name:Demos/Nodes spec:./demos/src/Nodes/**/*.spec.{js,ts}]) (push) Has been cancelled
build / test (20, map[name:Integration spec:./tests/cypress/integration/**/*.spec.{js,ts}]) (push) Has been cancelled
Publish / Release (20) (push) Has been cancelled
build / build (20) (push) Has been cancelled
This commit is contained in:
parent
942fd07b76
commit
3c82af3842
5
.changeset/long-pears-wash.md
Normal file
5
.changeset/long-pears-wash.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@tiptap/react": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
This changes useEditorState to use the useLayoutEffect hook instead of the useEffect hook, so that state that might render to the page can be committed in one pass instead of two.
|
@ -1,6 +1,6 @@
|
|||||||
import type { Editor } from '@tiptap/core'
|
import type { Editor } from '@tiptap/core'
|
||||||
import deepEqual from 'fast-deep-equal/es6/react'
|
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'
|
import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'
|
||||||
|
|
||||||
export type EditorStateSnapshot<TEditor extends Editor | null = Editor | null> = {
|
export type EditorStateSnapshot<TEditor extends Editor | null = Editor | null> = {
|
||||||
@ -164,7 +164,7 @@ export function useEditorState<TSelectorResult>(
|
|||||||
options.equalityFn ?? deepEqual,
|
options.equalityFn ?? deepEqual,
|
||||||
)
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
useLayoutEffect(() => {
|
||||||
return editorStateManager.watch(options.editor)
|
return editorStateManager.watch(options.editor)
|
||||||
}, [options.editor, editorStateManager])
|
}, [options.editor, editorStateManager])
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user