Skip to content

Commit

Permalink
Add flag to enable/disable expensive features. Disabling helps to iso…
Browse files Browse the repository at this point in the history
…late plugin performance issues
  • Loading branch information
jonathonherbert committed Jan 9, 2025
1 parent 31d5981 commit e4771d0
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions demo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ import {
} from "./sampleElements";
import type { WindowType } from "./types";

// Enable collaboration and serialisation. Disabling can be useful when measuring performance improvements.
const enableExpensiveFeatures = false;

// Only show focus when the user is keyboard navigating, not when
// they click a text field.
FocusStyleManager.onlyShowFocusOnTabs();
Expand Down Expand Up @@ -350,6 +353,14 @@ const createEditor = (server: CollabServer) => {
}
});

const expensivePlugins = enableExpensiveFeatures
? [
collabPlugin,
updateElementDataPlugin,
createSelectionCollabPlugin(clientID),
]
: [];

const view = new EditorView(editorElement, {
state: EditorState.create({
doc: isFirstEditor ? get() : firstEditor?.state.doc,
Expand All @@ -359,9 +370,7 @@ const createEditor = (server: CollabServer) => {
testDecorationPlugin,
testWidgetDecorationPlugin,
testInnerEditorEventPropagationPlugin,
collabPlugin,
updateElementDataPlugin,
createSelectionCollabPlugin(clientID),
...expensivePlugins,
],
}),
});
Expand Down Expand Up @@ -515,7 +524,9 @@ const createEditor = (server: CollabServer) => {
const server = new CollabServer();
firstEditor = createEditor(server);
const doc = firstEditor.state.doc;
server.init(doc);
if (enableExpensiveFeatures) {
server.init(doc);
}

// Add more editors
const addEditorButton = document.createElement("button");
Expand Down

0 comments on commit e4771d0

Please sign in to comment.