Skip to content

Commit b10ca4e

Browse files
committed
Fix race condition with live
1 parent 012220f commit b10ca4e

File tree

1 file changed

+16
-10
lines changed
  • packages/app/src/app/overmind/effects/vscode

1 file changed

+16
-10
lines changed

packages/app/src/app/overmind/effects/vscode/index.ts

+16-10
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,22 @@ export class VSCodeEffect {
157157
]).then(() => this.loadEditor(window.monaco, container));
158158
});
159159

160-
options.reaction(
161-
state =>
162-
!state.live.isLive ||
163-
state.live.roomInfo?.mode === 'open' ||
164-
(state.live.roomInfo?.mode === 'classroom' &&
165-
state.live.isCurrentEditor),
166-
canEdit => {
167-
this.setReadOnly(!canEdit);
168-
}
169-
);
160+
// Only set the read only state when the editor is initialized.
161+
this.initialized.then(() => {
162+
// ReadOnly mode is derivative, it's based on a couple conditions, of which the
163+
// most important one is Live. If you're in a classroom live session as spectator,
164+
// you should not be allowed to edit.
165+
options.reaction(
166+
state =>
167+
!state.live.isLive ||
168+
state.live.roomInfo?.mode === 'open' ||
169+
(state.live.roomInfo?.mode === 'classroom' &&
170+
state.live.isCurrentEditor),
171+
canEdit => {
172+
this.setReadOnly(!canEdit);
173+
}
174+
);
175+
});
170176

171177
return this.initialized;
172178
}

0 commit comments

Comments
 (0)