Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/cursor-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ export const LoroCursorPlugin = (
const awarenessListener = (_: any, origin: string) => {
if (origin !== "local") {
setTimeout(() => {
if (view.isDestroyed) {
return;
}
let tr = view.state.tr;
tr.setMeta(loroCursorPluginKey, {
awarenessUpdated: true,
Expand Down
12 changes: 12 additions & 0 deletions src/sync-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ export const LoroSyncPlugin = (props: LoroSyncPluginProps): Plugin => {

// This is called when the plugin's state is associated with an editor view
function init(view: EditorView) {
if (view.isDestroyed) {
return;
}

const state = loroSyncPluginKey.getState(view.state) as LoroSyncPluginState;

let docSubscription = state.docSubscription;
Expand Down Expand Up @@ -169,6 +173,10 @@ function init(view: EditorView) {
}

function updateNodeOnLoroEvent(view: EditorView, event: LoroEventBatch) {
if (view.isDestroyed) {
return;
}

const state = loroSyncPluginKey.getState(view.state) as LoroSyncPluginState;
state.changedBy = event.by;
if (event.by === "local" && event.origin !== "undo") {
Expand Down Expand Up @@ -219,6 +227,10 @@ export function syncCursorsToPmSelection(
anchor: Cursor,
focus?: Cursor,
) {
if (view.isDestroyed) {
return;
}

const state = loroSyncPluginKey.getState(view.state);
if (!state) {
return;
Expand Down