chore: Remove collab attribution

Signed-off-by: Mark Tolmacs <mark@lazycat.hu>
This commit is contained in:
Mark Tolmacs committed 2026-08-10 16:15:17 +00:00
1 parent 8d0a092f5b
commit 2bedc882ea
3 files changed
+19 -77

No files matched your search

-3
View File
@@ -96,7 +96,6 @@ import {
} from "./app_constants";
import Collab, {
collabAPIAtom,
collabCurrentUserAtom,
isCollaboratingAtom,
isOfflineAtom,
userToFollowAtom,
@@ -414,7 +413,6 @@ const ExcalidrawWrapper = () => {
});
const collabError = useAtomValue(collabErrorIndicatorAtom);
const userToFollow = useAtomValue(userToFollowAtom);
const collabCurrentUser = useAtomValue(collabCurrentUserAtom);
const viewportStatusFrame = useMemo(
() =>
@@ -956,7 +954,6 @@ const ExcalidrawWrapper = () => {
onExport={onExport}
initialData={initialStatePromiseRef.current.promise}
isCollaborating={isCollaborating}
currentUser={collabCurrentUser ?? undefined}
onPointerUpdate={collabAPI?.onPointerUpdate}
UIOptions={{
canvasActions: {
-32
View File
@@ -99,15 +99,6 @@ import type {
export const collabAPIAtom = atom<CollabAPI | null>(null);
export const isCollaboratingAtom = atom(false);
export const isOfflineAtom = atom(false);
/**
* identity of the local client during a collab session, keyed by the socket id
* so that peers can resolve it against their collaborators map. `null` when
* not collaborating (or before the socket connects).
*/
export const collabCurrentUserAtom = atom<{
id: string;
name: string;
} | null>(null);
interface CollabState {
errorMessage: string | null;
@@ -301,20 +292,6 @@ class Collab extends PureComponent<CollabProps, CollabState> {
appJotaiStore.set(isCollaboratingAtom, isCollaborating);
};
/**
* (re)computes the local client identity. Called whenever the socket
* (re)connects — reconnecting assigns a new socket id — and whenever the
* username changes.
*/
private setCurrentUser = (username: string = this.state.username) => {
const socketId = this.portal.socket?.id;
appJotaiStore.set(
collabCurrentUserAtom,
socketId ? { id: socketId, name: username } : null,
);
};
private onUnload = () => {
this.destroySocketClient({ isUnload: true });
};
@@ -442,7 +419,6 @@ class Collab extends PureComponent<CollabProps, CollabState> {
this.setIsCollaborating(false);
this.setActiveRoomLink(null);
appJotaiStore.set(userToFollowAtom, null);
appJotaiStore.set(collabCurrentUserAtom, null);
this.collaborators = new Map();
this.excalidrawAPI.updateScene({
collaborators: this.collaborators,
@@ -563,12 +539,6 @@ class Collab extends PureComponent<CollabProps, CollabState> {
);
this.portal.socket.once("connect_error", fallbackInitializationHandler);
// fires on the initial connection and on every reconnect, which is
// when the socket id (our identity during the session) is (re)assigned
this.portal.socket.on("connect", () => this.setCurrentUser());
// in case we're already connected by the time we subscribe
this.setCurrentUser();
} catch (error: any) {
console.error(error);
this.setErrorDialog(error.message);
@@ -1062,8 +1032,6 @@ class Collab extends PureComponent<CollabProps, CollabState> {
if (socketId && this.collaborators.has(socketId)) {
this.updateCollaborator(socketId, { username });
}
this.setCurrentUser(username);
};
getUsername = () => this.state.username;
@@ -1,10 +1,9 @@
import { UI } from "@excalidraw/excalidraw/tests/helpers/ui";
import { act, render, waitFor } from "@excalidraw/excalidraw/tests/test-utils";
import { vi } from "vitest";
import ExcalidrawApp from "../App";
import { appJotaiStore } from "../app-jotai";
import { STORAGE_KEYS } from "../app_constants";
import { collabCurrentUserAtom } from "../collab/Collab";
const { h } = window;
@@ -77,20 +76,30 @@ vi.mock("socket.io-client", () => {
};
});
describe("collab currentUser", () => {
describe("no authorship attribution in the app", () => {
beforeEach(() => {
socketMock.reset();
appJotaiStore.set(collabCurrentUserAtom, null);
localStorage.setItem(
STORAGE_KEYS.LOCAL_STORAGE_COLLAB,
JSON.stringify({ username: "Test User" }),
);
});
it("should pass the socket id & username as currentUser while collaborating", async () => {
it("should not stamp authorship onto locally created elements", async () => {
await render(<ExcalidrawApp />);
UI.createElement("rectangle", { x: 10, y: 10 });
expect(h.elements.length).toBe(1);
expect(h.elements[0].createdBy).toBeNull();
expect(h.elements[0].updatedBy).toBeNull();
});
// authorship is a host-app concern - excalidraw.com never identifies the
// local user to the editor, so nothing it does may ever author an element
it("should never pass a currentUser, not even while collaborating", async () => {
await render(<ExcalidrawApp />);
expect(appJotaiStore.get(collabCurrentUserAtom)).toBe(null);
expect(h.app.props.currentUser).toBe(undefined);
// returns a promise resolved on scene init, hence not awaited
@@ -100,57 +109,25 @@ describe("collab currentUser", () => {
expect(window.collab.portal.socket).toBeTruthy();
});
// no identity until the socket connects
expect(appJotaiStore.get(collabCurrentUserAtom)).toBe(null);
expect(h.app.props.currentUser).toBe(undefined);
await act(async () => {
socketMock.id = "socket_1";
socketMock.trigger("connect");
});
await waitFor(() => {
expect(appJotaiStore.get(collabCurrentUserAtom)).toEqual({
id: "socket_1",
name: "Test User",
});
expect(h.app.props.currentUser).toEqual({
id: "socket_1",
name: "Test User",
});
});
expect(h.app.props.currentUser).toBe(undefined);
// username changes are reflected
await act(async () => {
window.collab.setUsername("Renamed User");
});
await waitFor(() => {
expect(h.app.props.currentUser).toEqual({
id: "socket_1",
name: "Renamed User",
});
});
// reconnecting assigns a new socket id
await act(async () => {
socketMock.id = "socket_2";
socketMock.trigger("connect");
});
await waitFor(() => {
expect(h.app.props.currentUser).toEqual({
id: "socket_2",
name: "Renamed User",
});
});
expect(h.app.props.currentUser).toBe(undefined);
await act(async () => {
window.collab.stopCollaboration(false);
});
await waitFor(() => {
expect(appJotaiStore.get(collabCurrentUserAtom)).toBe(null);
expect(h.app.props.currentUser).toBe(undefined);
});
expect(h.app.props.currentUser).toBe(undefined);
});
});