-
Notifications
You must be signed in to change notification settings - Fork 4
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
Issue when using with tiptap collaboration cursor #7
Comments
Hi @seleckis, in this code snippet you posted, are you attempting to update the user presence every time the value of
This is a nice way to ensure |
Well, I need to set user data for CollaborationCursor extension. According to documentation it should be set when initializing editor with extensions: const self = useSelf();
const extensions = useMemo(() => [
Collaboration.configure({
document: ydoc,
fragment: yField,
}),
CollaborationCursor.configure({
provider: yprovider,
user: {
user: self?.username,
color: self?.color,
},
}),
], [yField, self]);
const editor = useEditor({
extensions,
}); but in this case sometimes self?.username returns clientID of current user and does not update user data when I have broken down the object So do you suggest to use useEffect(() => {
const onChange = ({ added, updated, removed }) => {
console.log(added, updated, removed);
})
awareness.on("change", onChange);
return () => {
awareness.off("change", onChange);
};
}, []); in this case it gives me only Alright, I've ended up with this solution: export const useAwareness = (cb: (self: YUser | null) => void) => {
useEffect(() => {
const onChange = ({ updated }: { updated: number[] }) => {
if (updated.includes(awareness.clientID)) {
const self = awareness.getLocalState();
cb(self as YUser);
}
};
awareness.on("change", onChange);
return () => {
awareness.off("change", onChange);
};
}, [cb]);
};
...
useAwareness((self) => {
if (!editor || !self?.username) return;
const { username, color } = self;
editor.commands.updateUser({
name: username,
color,
});
}); This works well, updates tiptap collaboration cursor with correct data and does not force websocket to send infinite messages. I was just hoping |
useSelf works well in most situations. But when I use it with TipTap editor and CollaborationCursor extension here comes an issue:
In a component that renders tipTap editor I need to update the presence of the user like this:
Unfortunately this code makes tiptap editor opened websocket to go mad and infinity send a huge amount of messages.
I have create this hook:
Now update is working as expected and there is no infinite loop of messages anymore.
Should this be added in the y-presence lib? What do you think?
The text was updated successfully, but these errors were encountered: