Skip to content

React compiler safe#513

Open
shysteph wants to merge 3 commits intosjdemartini:mainfrom
shysteph:react-compiler
Open

React compiler safe#513
shysteph wants to merge 3 commits intosjdemartini:mainfrom
shysteph:react-compiler

Conversation

@shysteph
Copy link
Contributor

This updates the project to use useEditorState to get components updated when the editor changes state so projects using react compiler will pick up these changes. It also upgrades to react 19 and switches from the react-swc to just the plain react plugin in vite to enable react compiler for the demo.
It also makes useRichTextEditorContext always return an Editor instance which is required by useEditorState instead of allowing undefined. It protects the outer components from rendering if there is no editor provided in order to still be safe.
I confirmed at the beginning of development that the demo was indeed broken when I intially turned on the compiler, for example the add link feature and buttons not updating when the active element changed. It now works correctly.
useEditorState is also recommended in the docs and example components in @tiptap/react.
https://tiptap.dev/docs/guides/performance#use-useeditorstate-to-prevent-unnecessary-re-renders

* Use useEditorState to get components to update themselves when editor is updated
* Upgrade to react 19 for development so the demo site can be compiled with react compiler this does mean using babel not swc for now
* Make useRichTextEditorContext always return an Editor not null | undefined
* Make outer components not render if useEditor returns undefined per V2 of tiptap

# Conflicts:
#	src/controls/MenuButtonHighlightColor.tsx
@shysteph
Copy link
Contributor Author

shysteph commented Feb 2, 2026

I think this may also allow turning off shouldRerenderOnTransaction since the recommended solution is to use useEditorState. But that would break V2 more?

@sjdemartini
Copy link
Owner

Yes, a primary reason to use useEditorState it is to turn off shouldRerenderOnTransaction for performance benefits. I filed an issue around this specifically in #425. It will break compatibility for older Tiptap v2 versions, so I'm inclined to pursue this for a major version bump only. This is a fairly significant refactor, so I haven't had time to dig into it yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants