Skip to content

Conversation

@erickzhao
Copy link
Member

@erickzhao erickzhao commented Nov 19, 2025

A little quality of life feature. Does a small Monaco minor version bump such that we get access to the editor.onDidChangeMarkers API.

I'd recommend reviewing with Hide Whitespace on btw. This will also have some annoying merge conflicts with #1811.

Screen.Recording.2025-11-18.at.20.38.14.mov

@socket-security
Copy link

socket-security bot commented Nov 19, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatednpm/​monaco-editor-webpack-plugin@​2.1.0 ⏵ 3.1.0100 +1100100 +283 -5100
Updatednpm/​monaco-editor@​0.21.3 ⏵ 0.22.3100 +110099 +199 -1100

View full report

@coveralls
Copy link

coveralls commented Nov 19, 2025

Coverage Status

coverage: 79.596% (+0.07%) from 79.531%
when pulling f245417 on erick/markers
into 48bf04e on main.

@erickzhao erickzhao marked this pull request as ready for review November 19, 2025 04:47
@erickzhao erickzhao requested review from a team and codebytere as code owners November 19, 2025 04:47
}
},
);
window.monaco.editor.onDidChangeMarkers(this.setSeverityLevels.bind(this));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: does this binding need to be cleaned up on destroy/ in the constructor?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a good callout. After looking a bit more, I don't think there's an easy way of disposing of this callback since JavaScript classes don't provide a lifecycle hook for when the class gets destroyed (in the same way that React does when a component gets unmounted).

Since EditorMosaic never gets destroyed in a Fiddle instance (we keep the same instance and recycle editors whenever possible), I think the potential for a large memory leak is reduced (but I could be wrong).

If this proves to be a problem, we might want to look into the FinalizationRegistry API to manually call the dispose() function when the EditorMosaic object gets GCed.

The whole "Avoid where possible" section in that API makes me just a bit wary for now.

Happy for pushback on this assessment, though.

<RemoveButton id={id} appState={appState} />
public render() {
const { editorMosaic } = this.props.appState;
const severityLevel = toJS(editorMosaic.editorSeverityMap);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: can we just have const severityLevel = editorMosaic.editorSeverityMap here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The toJS call here is to force a re-render when the values change.

Due to the way renderToolbar() is only called deep in the third-party Mosaic component, I don't think React + MobX is able to pick up the changes and re-render without this hack.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment indicating this

// set a URI for each editor for stable identification for monaco features
const uri = monaco.Uri.parse(`inmemory://fiddle/${id}`);
const maybeModel = monaco.editor.getModel(uri);
const model = maybeModel ?? monaco.editor.createModel(value, language, uri);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blocking(?): I believe we have to update the content in maybeModel.

example:

  1. editorMosaic.set('main.js', 'foo');
  2. user edits main.js, 'bar'
  3. if user loads another fiddle, where main.js: 'foobar'. This is may be a bug, where we use maybeModel and thus the new fiddle opens with 'bar' rather than the expected 'foobar'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me know if this is unclear, I could be wrong as well

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah pretty sure you're right. That repros in testing. Will fix soon!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed ba71f34

The unit tests were falsely passing before because I didn't mock the getModel() call properly beforehand and maybeModel was always undefined. I verified that the new test fails without the refactor. 👍

@erickzhao erickzhao requested a review from georgexu99 November 20, 2025 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants