Multiple text-areas being added after an update event

Change your JS to this:

let editor;
function update() {
  var select = $('#lang').val();
  editor = editor ?? CodeMirror.fromTextArea($('#text'), {
      theme: "blackboard",
  });
  editor.setOption('mode', select);
}
update();

This makes it so if editor already exists, it is not created again, but instead re-used.