[Bug]: The React Installation Example in https://tiptap.dev/installation/react seems to be broken in multiple places, especially with vite and vitest #4618
My project team has an existing React/TypeScript/Vite project, and we are looking for a WYSIWYG editor to add for the next stage, so I decided to investigate TipTap. There is an installation example for React that I'd expect to "work out of the box" at https://tiptap.dev/installation/react - 'The complete setup (optional)", so I decided to copy and paste the example into existing code.
However, I have identified two issues where TypeScript typing is broken, and two issues where it has broken the vitest testing framework, which we use. So there are four issues. I have replicated this with a bare bones React/TypeScript/Vite project, which I will put on GitHub. I will start with the TypeScript issue.
Argument of type '{ types: string[]; }' is not assignable to parameter of type 'Partial<TextStyleOptions>'.
Object literal may only specify known properties, and 'types' does not exist in type 'Partial<TextStyleOptions>'.ts(2345)
(property) types: string[]
I can of course change the line to make the errors go away, but it really shouldn't be necessary:
TextStyle.configure({ types: [ListItem.name] } as Partial<TextStyleOptions>),
Issue 3 is more serious. At the moment, I have an App that contains this code:
When I take out the <pre> element and its contents, that error goes away, and the test works. Note: there is no problem with the app at all, but vitest has a problem.
The fourth error is from the code example page (3. Create a new component). Let's assume that I don't have that dodgy <pre> element instead, but I have this code:
<EditorProvider slotBefore={<MenuBar />} extensions={extensions} content={content}>
<FloatingMenu>This is the floating menu</FloatingMenu>
<BubbleMenu>This is the bubble menu</BubbleMenu>
</EditorProvider>
Again - this is a situation where the app works, but vitest doesn't.
I have created a repository that replicates the third error (the ((intermediate value)(intermediate value)(intermediate value) || []) is not iterable). I wanted a repository, as it replicates the existing conditions that our project team are using (Vite, Vitest, use of HappyDom) without extraneous stuff. To repliacate the other errors, please edit as necessary.
Here's a nice code example that I copy and paste into my existing code without any dramas. There are no problems in TypeScript or testing, and we decide to choose TipTap as the rich text editor for our project.
Anything to add? (optional)
Thank you very much to the team for looking into it.
Did you update your dependencies?
[X] Yes, I’ve updated my dependencies to use the latest version of all packages.
Which packages did you experience the bug in?
core, react
What Tiptap version are you using?
2.1.12
What’s the bug you are facing?
My project team has an existing React/TypeScript/Vite project, and we are looking for a WYSIWYG editor to add for the next stage, so I decided to investigate TipTap. There is an installation example for React that I'd expect to "work out of the box" at https://tiptap.dev/installation/react - 'The complete setup (optional)", so I decided to copy and paste the example into existing code.
However, I have identified two issues where TypeScript typing is broken, and two issues where it has broken the vitest testing framework, which we use. So there are four issues. I have replicated this with a bare bones React/TypeScript/Vite project, which I will put on GitHub. I will start with the TypeScript issue.
Issue 1 - you code example:
Give me this error:
To fix it, I need to put in a dummy element
{' '}
. (It doesn't do anything, but it really shouldn't be necessary.)Issue 2 - this code example:
Gives me this error:
I can of course change the line to make the errors go away, but it really shouldn't be necessary:
Issue 3 is more serious. At the moment, I have an
App
that contains this code:So I have a simple test in
App.test.tsx
:Now in the
TipTapEditor
class there is acontents
constant, with the following piece inside itWhen I run the Vitest test, I get:
When I take out the
<pre>
element and its contents, that error goes away, and the test works. Note: there is no problem with the app at all, but vitest has a problem.The fourth error is from the code example page (3. Create a new component). Let's assume that I don't have that dodgy
<pre>
element instead, but I have this code:I get:
Again - this is a situation where the app works, but vitest doesn't.
I have created a repository that replicates the third error (the
((intermediate value)(intermediate value)(intermediate value) || []) is not iterable
). I wanted a repository, as it replicates the existing conditions that our project team are using (Vite, Vitest, use of HappyDom) without extraneous stuff. To repliacate the other errors, please edit as necessary.What browser are you using?
Firefox
Code example
https://github.com/peterkmurphy/vite-with-tiptap
What did you expect to happen?
Here's a nice code example that I copy and paste into my existing code without any dramas. There are no problems in TypeScript or testing, and we decide to choose TipTap as the rich text editor for our project.
Anything to add? (optional)
Thank you very much to the team for looking into it.
Did you update your dependencies?
Are you sponsoring us?