-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat(react): introduce <Tiptap /> component for easier integration
#6917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: e17bf4b The changes in this PR will be included in the next version bump. This PR includes changesets to release 69 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for tiptap-embed ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
@tiptap/extension-character-count
@tiptap/extension-dropcursor
@tiptap/extension-gapcursor
@tiptap/extension-focus
@tiptap/extension-history
@tiptap/extension-list-keymap
@tiptap/extension-list-item
@tiptap/extension-placeholder
@tiptap/extension-table-header
@tiptap/extension-table-cell
@tiptap/extension-table-row
@tiptap/extension-task-item
@tiptap/extension-task-list
@tiptap/extension-blockquote
@tiptap/extension-bold
@tiptap/core
@tiptap/extension-bubble-menu
@tiptap/extension-bullet-list
@tiptap/extension-code-block
@tiptap/extension-code
@tiptap/extension-code-block-lowlight
@tiptap/extension-collaboration
@tiptap/extension-collaboration-caret
@tiptap/extension-color
@tiptap/extension-details
@tiptap/extension-document
@tiptap/extension-drag-handle
@tiptap/extension-drag-handle-react
@tiptap/extension-drag-handle-vue-3
@tiptap/extension-drag-handle-vue-2
@tiptap/extension-emoji
@tiptap/extension-file-handler
@tiptap/extension-floating-menu
@tiptap/extension-font-family
@tiptap/extension-hard-break
@tiptap/extension-highlight
@tiptap/extension-heading
@tiptap/extension-horizontal-rule
@tiptap/extension-image
@tiptap/extension-invisible-characters
@tiptap/extension-italic
@tiptap/extension-link
@tiptap/extension-mathematics
@tiptap/extension-list
@tiptap/extension-mention
@tiptap/extension-node-range
@tiptap/extension-ordered-list
@tiptap/extension-paragraph
@tiptap/extension-strike
@tiptap/extension-subscript
@tiptap/extension-superscript
@tiptap/extension-table
@tiptap/extension-table-of-contents
@tiptap/extension-text
@tiptap/extension-text-align
@tiptap/extension-typography
@tiptap/extension-underline
@tiptap/extension-text-style
@tiptap/extension-unique-id
@tiptap/extension-youtube
@tiptap/extensions
@tiptap/html
@tiptap/react
@tiptap/pm
@tiptap/starter-kit
@tiptap/static-renderer
@tiptap/vue-2
@tiptap/suggestion
@tiptap/vue-3
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a new declarative React component API for Tiptap that provides a more ergonomic, component-first approach to editor integration while maintaining backward compatibility with the existing imperative API.
- Adds new
<Tiptap />component with context-based editor sharing and subcomponents for content, menus, and loading states - Introduces new hooks (
useTiptap,useTiptapState) for accessing editor state in child components - Improves robustness in core focus command with better error handling for unmounted editor views
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/react/src/index.ts | Exports the new Tiptap component and related utilities |
| packages/react/src/Tiptap.tsx | Implements the complete new React integration with context, components, and hooks |
| packages/core/src/commands/focus.ts | Adds try-catch error handling for view.hasFocus() when view is not mounted |
| .changeset/react-tiptap-new-setup.md | Documents the new React integration feature with usage examples and migration guidance |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love this approach, it could make my code simpler.
I'd like to ask whether the isCreated property is necessary. Another doubt I have is whether the Tiptap component could be called TiptapProvider to let the React developer know that it is a context provider
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is some overlap between this feature and this one:
https://tiptap.dev/docs/editor/getting-started/install/react#using-the-editorcontext
Co-authored-by: Copilot <[email protected]>
Yes - this will also become obsolete. It was the first draft at implementing React Context but since you can do:
I wanted to streamline it and make it more straight forward. So with 4.0.0 I'd get rid of at least 2 and 3. Users should still be able to just create instances via |
I understand your thought but I think lots of other libraries already do something similar (just checking Radix or FloatingUI for example - you just use We could allow both - |
Changes Overview
This pull request introduces a new, optional React integration for Tiptap, providing a declarative
<Tiptap />component that simplifies editor setup in React applications. This is an additive change, offering a more ergonomic, component-first API while keeping the existing imperative API fully supported for this major version. The update also includes minor robustness improvements in the core command logic.With this new approach, we can later deprecate the current ways of setting up an editor that can be confusing and allows multiple ways that can lead to implementation errors.
Example:
As you can see, this approach automatically provides a Context for all sub-components, that components can hook in.
<Tiptap />- The wrapper that provides context<Tiptap.Loading />- A loading wrapper that can be used to render a loading spinner / message while the editor is initializing, setting up. Future plan is to wrap this together with collaborative features to make sure editors are only rendered when everything is initialized<Tiptap.Content />- The replacement for<EditorContent editor={editor} /><Tiptap.BubbleMenu />- The replacement for<BubbleMenu editor={editor} /><Tiptap.FloatingMenu />- The replacement for<FloatingMenu editor={editor} />useTiptap()- A hook that can be used in sub-components to retrieve the Tiptap editor instance from childrenconst { editor } = useTiptap()useTiptapState(selectorFn)- A replacement foruseEditorStatewhich can be used to directly retrieve editor state from the current editorImplementation Approach
React integration and API improvements:
Tiptapcomponent and related context/hooks (TiptapContext,useTiptap,useTiptapState) topackages/react/src/Tiptap.tsx, enabling declarative, prop-driven editor setup and composition in React apps. This includes subcomponents for content, loading state, and menus.Tiptapcomponent and related utilities from the package entry point (packages/react/src/index.ts).Core robustness:
focuscommand (packages/core/src/commands/focus.ts) to gracefully handle cases where the editor view is not yet mounted, avoiding runtime errors.Additional Notes
Checklist