google / mesop

Rapidly build AI apps in Python
https://google.github.io/mesop/
Apache License 2.0
5.22k stars 246 forks source link

Weird error message when trying to create webcomponent for Mesop #637

Open richard-to opened 1 month ago

richard-to commented 1 month ago

Here's the error message I keep getting:

Screenshot 2024-07-18 at 3 18 13 PM

It doesn't happen every time though. Occasionally I can get it to show a different error message.

This error message seems to appear when there is an error (but only certain types of errors it seems) in the javascript. This error occurs in dev mode in Mesop (via Pip) and Mesop with Bazel. It does not show up in Prod mode for Mesop via Pip

Example code:

import {
  LitElement,
  html,
} from 'https://cdn.jsdelivr.net/gh/lit/dist@3/core/lit-core.min.js';

import 'https://cdnjs.cloudflare.com/ajax/libs/codemirror/6.65.7/codemirror.js';
import 'https://cdnjs.cloudflare.com/ajax/libs/codemirror/6.65.7/mode/javascript/javascript.js';

class CodeEditorComponent extends LitElement {
  // Comment this properties object out and the code will work
  static properties = {
    code: ({type: String} = 'Hello World!'),
    codeChanged: {type: String},
  };

  constructor() {
    super();
    this.editorView = null;
  }

  createRenderRoot() {
    // Render in light DOM so firebase-ui-auth works.
    return this;
  }

  firstUpdated() {
    this.renderEditor();
  }

  renderEditor() {
    this.editorView = CodeMirror.fromTextArea(this.querySelector('#editor'), {
      mode: 'javascript',
      lineNumbers: true,
      theme: 'default',
      readOnly: false,
    });
  }

  render() {
    return html` <textarea id="editor">
function() { console.log('hello world'); </textarea
    >`;
  }
}

customElements.define('code-editor-component', CodeEditorComponent);
wwwillchen commented 1 month ago

Looks like it's coming from this line: https://github.com/google/mesop/blob/de8fa471c8ecb5da0add9c0e4b3f735ad54acb07/mesop/web/src/services/channel.ts#L182

i'm surprised there's a difference between prod mode and editor mode.