Repository navigation
Description
Describe the bug
Hello and thank you for the work on BlockNote!
It seems that undo / redo (Ctrl + Z / Ctrl + Y) are not working when the collaboration feature with Yjs is enabled.
When enabling collaboration with a minimal YJsProvider, Ctrl + Z does nothing. If we comment the collaboration part of the config it's working again.
Also, when trying to implement it by hand with the following code, it's still not working:
const undoHandler = useCallback((e: KeyboardEvent) => {
if ((e.metaKey || e.ctrlKey) && (e.key === 'z' || e.key === 'Z')) {
console.log('undo'); // displayed
editor.undo(); // <- NOT WORKING
}
}, []);
useWindowEvent('keydown', undoHandler);To Reproduce
Here is a minimal reproduction in a sandbox: https://stackblitz.com/edit/github-qp3au5av?file=src%2FApp.tsx
And the code, in case the sandbox is not working:
App.jsx
import '@blocknote/core/fonts/inter.css';
import { BlockNoteView } from '@blocknote/mantine';
import '@blocknote/mantine/style.css';
import { useCreateBlockNote } from '@blocknote/react';
import * as Y from 'yjs';
export default function App() {
const ydoc = new Y.Doc();
const yLoggingProvider = new YProvider(ydoc);
const editor = useCreateBlockNote({
collaboration: {
provider: yLoggingProvider,
fragment: ydoc.getXmlFragment('blocks'),
user: {
name: 'My Username',
color: '#ff0000',
},
// showCursorLabels: 'always',
},
});
// Renders the editor instance using a React component.
return <BlockNoteView editor={editor} />;
}
export class YProvider {
private doc: Y.Doc;
private name: string;
constructor(doc: Y.Doc, name = 'YProvider') {
this.doc = doc;
this.name = name;
this.doc.on('update', this.onLocalUpdate);
console.log(`[${this.name}] provider started`);
}
private onLocalUpdate = (update: Uint8Array, origin: any) => {
Y.applyUpdate(this.doc, update);
};
/**
* Apply a received update from an external source.
* This bypasses the debounce and applies immediately.
*/
public receiveUpdate(update: Uint8Array): void {
Y.applyUpdate(this.doc, update, `${this.name}-external`);
}
public destroy(): void {
this.doc.off('update', this.onLocalUpdate);
}
}Alternatively, you can try with the official WebrtcProvider as shown in the doc here: https://www.blocknotejs.org/docs/features/collaboration
const provider = new WebrtcProvider("my-document-id", ydoc);
const editor = useCreateBlockNote({
collaboration: {
provider: provider,
// Where to store BlockNote data in the Y.Doc:
fragment: ydoc.getXmlFragment("blocks"),
// Information (name and color) for this user:
user: {
name: "My Username",
color: "#ff0000",
},
// showCursorLabels: 'always',
}
});It's not working.
Misc
- Node version: 25.2
- Package manager: npm
- Browser: It's not working with multiple browsers
- I'm a sponsor and would appreciate if you could look into this sooner than later 💖
Activity
nperez0111 commentedon Dec 9, 2025
Hm, @notABot101010 I think what is happening here is that your set up for the ydoc provider creates a new instance each time and you are running the editor within a strict mode app.
This setup works for me.
I ran this on the latest version that is on main, so if it does not work for you, I am going to cut a release later today that you can try and it should work for you the same way that it works for me
notABot101010 commentedon Dec 9, 2025
Hey @nperez0111 , thank you for the quick answer!
I can confirm that the code your provided is not working with a fresh
react-tsvitejs app and if we comment thecollaborationconfiguration it's working.main.tsxindex.cssI will provide an update once the next version of BlockNote is released.
nperez0111 commentedon Dec 9, 2025
Sure, here is the latest version: https://github.com/TypeCellOS/BlockNote/releases/tag/v0.44.2
notABot101010 commentedon Dec 9, 2025
@nperez0111 Thank you!
Unfortunately, even with version
0.44.2, it's still not working with the exact code mentioned above, but if I comment the collaboration configuration it's working 🤔Could you try to reproduce with a new from scratch project and using
@blocknotepackages from npm (npm create vite@latest blocknote-collab-test -- --template react-tsI'm rather puzzled, so current hypothesis is that a recent update may have broken the feature and that your local environment is using older versions of the packages.
nperez0111 commentedon Dec 9, 2025
You are right, I'm also running into issues getting this to run in the codesandbox. When I removed your provider, it seems to work correctly though. So I guess it is something to do with that maybe?
I ran this, and it worked @notABot101010
notABot101010 commentedon Dec 10, 2025
@nperez0111 that's surprising because running this exact code in a sandbox (https://stackblitz.com/edit/github-zzgxsmeg?file=main.tsx) is not working.
Also, if we use the exact provider mentioned in the docs here: https://www.blocknotejs.org/docs/features/collaboration
It's not working with a blank project and the latest version of Blocknote.
I may have identified the source of the issue:
BlockNote/packages/core/src/extensions/Collaboration/YUndo.ts
Line 7 in 356a3ef
I believe that the
trackedOriginsshould not be[editor].Also this file has been updated just last week which may indicate why the breakage is recent.
Otherwise, the issue may come from the fact that the
YUndoextension depends on theYCursorextension, but hereBlockNote/packages/core/src/editor/managers/ExtensionManager/extensions.ts
Line 194 in 356a3ef
The YCursor extension is enabled only if the collaboration provider has an
awarenessfield.Could we reopen the issue please? I believe that the bug is real.
You can clean this repo, install, build and run the
examples/07-collaboration/01-partykitproject to confirm that it's not working.notABot101010 commentedon Dec 10, 2025
@nperez0111 I've found 2 solutions to this bug, I will let you chose which one is the most relevant, or if more work is needed.
From my initial testing, both are working, but I'm not sure which one is the cleanest.
Solution 1: Always enable HistoryExtension
in
extensions.tsin
YUndo.ts:in
StateManager.tsSolution 2: Apply the Tiptap workaround for y-prosemirror issues #114 and #102
in
YUndo.tsnperez0111 commentedon Dec 10, 2025
@notABot101010, you may be onto something with the awareness for the provider. I will take a look at that
nperez0111 commentedon Dec 10, 2025
We cannot enable the prosemirror-history extension at the same time as the y-undo plugin. So, I'm looking into options there. I don't understand why it is acting different in my dev environment
notABot101010 commentedon Dec 10, 2025
It seems that there is some really weird interaction between Yjs, prosemirror and the various plumbing layers.
May also be related to yjs/y-prosemirror#114 and yjs/y-prosemirror#102
I've spent a lot of time on this issue but I'm still really sure about where it can come from due to the many projects interacting together.
notABot101010 commentedon Dec 10, 2025
Also, I've tried to downgrade blocknote to version 0.42 but it was still not working.
Is there a way to get the exact version numbers of the dependencies used to build the website that is live at https://www.blocknotejs.org ?
Because undo / redo is working on the landing page with collaboration enabled, if an update (whether it be in Yjs or blocknote) broke the collaboration undo / redo, at least knowing the versions of when it was working may help.
nperez0111 commentedon Dec 11, 2025
https://github.com/TypeCellOS/BlockNote/blob/356a3ef7224fb0b4778a3b975ab84d5565344b62/pnpm-lock.yaml should have everything you need here
Yea, and no one else has reported issues with this, which makes me think that it is related to the provider having awareness setup on it or not. I'll open a PR with some changes that I think should help, but I just can't validate it for myself right now
1 remaining item
nperez0111 commentedon Dec 12, 2025
Did the PR resolve your issue? You should be able to run your project with the pkg.pr.new versions in the PR
fix: always include the cursor extension #2244 (#2260)
ysds commentedon Jan 7, 2026
@nperez0111
It seems this issue is still occurring.
I encountered this issue the other day when I upgraded to React 19. It does not occur in React 18, but it does occur in React 19.
nperez0111 commentedon Jan 7, 2026
@ysds I commented out React.Strictmode in your example and it works for me. So, this is due to Strictmode issue that we are tracking here: #2106
ysds commentedon Jan 13, 2026
@nperez0111
I updated to 0.46.1, but unfortunately, the issue does not seem to have been resolved.
https://stackblitz.com/edit/github-qp3au5av-gknouchr?file=package.json
ysds commentedon Jan 14, 2026
I was able to reproduce it locally as well.
It doesn’t seem to be reproducible with
pnpm devrun from the root directory.srikanthragh06 commentedon Mar 16, 2026
Hey, I have been facing this issue as well in my project and I was able to come up with a fix incase you are using blocknote and yjs together in your project.