tiptap: Uncaught TypeError: ystate is undefined when using Collaboration and CollaborationCursor and esbuild
What’s the bug you are facing?
Hi there. I’m using esbuild as the build system in my app, and found that I could not use both Collaboration and CollaborationCursor together without the app error-ing out with an Uncaught TypeError: ystate is undefined error. The code builds properly, and produces this error at runtime.
Investigation suggests that this is because both plugins are creating their own instances of the y-sync plugin, and then the creation of yState fails the second time because the key no longer matches the one in the state, resulting in an undefined yState.
Which browser was this experienced in? Are any special extensions installed?
Firefox 102.0.1, Chrome v103. No special extensions.
How can we reproduce the bug on our side?
A minimal repro is to take the code from the CollaborationCursor example from the documentation site, and use esbuild to bundle it (with the bundle: true param). The bundle should be produced successfully, but trying to run the bundle will fail.
I have a demo repository with that minimal repro here: https://github.com/a-morphous/tiptap-esbuild-collab-issue/
You can run npm run build and then npm run serve to see the error locally. Commenting out the use of CollaborationCursor will make the code in the repository run as expected.
Can you provide a CodeSandbox?
Unlikely, given that this is most likely a build issue; I’d be happy to try to create one if it would help, though.
What did you expect to happen?
The app builds and runs without producing any errors.
Anything to add? (optional)
It looks like the schema for adding multiple plugins into tiptap (or maybe prosemirror or yjs?) is causing a name mismatch with the state, as shown when I set a breakpoint when yState gets set:
It doesn’t error out if I take out the CollaborationCursor plugin, because the first time y-sync is created, the key and state names match; it’s only the second one onwards that fails.
Did you update your dependencies?
- Yes, I’ve updated my dependencies to use the latest version of all packages.
Are you sponsoring us?
- Yes, I’m a sponsor. 💖
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (2 by maintainers)
Hey there!
I know the Tiptap collaborative extension documentation can be a bit tricky, but don’t worry! If you’re looking to implement it on a React-based framework, the code I provided earlier is a great starting point.
It’s a basic setup that you can easily customize to meet your specific needs. And since it’s built with React, it will be a breeze to integrate with any React-based framework, including Next.js.
Oh, and here’s a quick styles.css file to get you going! 💻
I hope this helps you get started! If you have any other questions or need further clarification, don’t hesitate to ask. Good luck and happy coding! 😎
Thank you, @mmilad and @nmante. I finally got it working by pinning
y-prosemirrorto1.0.20.This is likely due to dependency mismatches. I had
y-prosemirrorinstalled with version 1.2.0, and tiptap 2.0.0-beta.218 packages. I was getting the ystate undefined error. The fix was to pin the y-prosemirror version to 1.0.20 like @mmilad said. Here’s my package.js for anyone curious. The relevant packages are tiptapy-*packages as well asyjs.Have the same issue here. I copy / pasted the code in this example, which is working fine until I try to use
@tiptap/extension-collaboration-cursorextension. Tried in versions 2.0.0-beta.214 - 2.0.0-beta.218.Getting the same error as @adrice727.
I also tried to install the
y-prosemirrordependency (1.2.0) without any success. After taking a look into the peer deps of@tiptap/extension-collaboration-cursorand@tiptap/extension-collaboration-cursor, i saw the they-prosemirrorversion requested as peerDeps are 1.0.20. Worked after installed that version.Thank @a-morphous
Yup that works! Thank you for the helpful guide @ owynreveon and info @ a-morphous, much appreciated. I have collaboration cursor working in all my environments (React and Vite) now.