Skip to content

Commit

Permalink
fix(playground): editor was losing state if value set before componen…
Browse files Browse the repository at this point in the history
…t was ready

this was noticeable every so often when opening a live sample in the playground
  • Loading branch information
LeoMcA committed Dec 11, 2024
1 parent e8bde75 commit c94cafa
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions client/src/playground/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,23 @@ export class PlayEditor extends LitElement {
super();
this.language = "";
this.colorScheme = "os-default";
this._value = "";
}

/** @param {string} value */
set value(value) {
let state = EditorState.create({
doc: value,
extensions: this._extensions(),
});
this._editor?.setState(state);
this._value = value;
if (this._editor) {
let state = EditorState.create({
doc: value,
extensions: this._extensions(),
});
this._editor.setState(state);
}
}

get value() {
return this._editor?.state.doc.toString() || "";
return this._editor ? this._editor.state.doc.toString() : this._value;
}

_extensions() {
Expand Down Expand Up @@ -125,6 +129,7 @@ export class PlayEditor extends LitElement {

firstUpdated() {
let startState = EditorState.create({
doc: this._value,
extensions: this._extensions(),
});
this._editor = new EditorView({
Expand Down

0 comments on commit c94cafa

Please sign in to comment.