marimo-team/marimo

ipyreact doesn't work properly

Closed this issue · 2 comments

Describe the bug

ipyreact is built on top of anywidget. It is setup so that all ipyreact widgets can share the same react-js context through their concept of a module. when trying my simple starter widget, whether defined through an import map (similar to what anywidget does) or using a module, I get JS errors around react-js.

The JS error looks like this

SyntaxError: missing ) in parenthetical [index-S77OjPaJ.js:31:195605](http://localhost:2718/assets/index-S77OjPaJ.js)

The relevant snippet of javascript

/**
 * @license React
 * react-dom.production.min.js
 *
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *  Line 31 follows, it is extremely long, so I will not include it
 */

Environment

{
"marimo": "0.9.20",
"OS": "Darwin",
"OS Version": "22.6.0",
"Processor": "arm",
"Python Version": "3.12.7",
"Binaries": {
"Browser": "131.0.6778.71",
"Node": "v18.20.4"
},
"Dependencies": {
"click": "8.1.7",
"docutils": "0.21.2",
"itsdangerous": "2.2.0",
"jedi": "0.19.2",
"markdown": "3.7",
"narwhals": "1.14.1",
"packaging": "24.1",
"psutil": "5.9.0",
"pygments": "2.18.0",
"pymdown-extensions": "10.12",
"pyyaml": "6.0.2",
"ruff": "0.7.4",
"starlette": "0.41.3",
"tomlkit": "0.13.2",
"typing-extensions": "4.12.2",
"uvicorn": "0.32.0",
"websockets": "12.0"
},
"Optional Dependencies": {
"anywidget": "0.9.13",
"pandas": "2.2.2"
}
}

Code to reproduce

I'm currently in the process of publishing the ipyreact_starter package. It really isn't meant to be on package repositories. I mostly use it for local testing of ipyreact.

git clone https://github.com/paddymul/ipyreact-starter.git
cd ipyreact-starter
./full_build.sh # builds all of the JS, and creates the wheel
pip install dist/ipyreact_starter-0.0.1-py3-none-any.whl

In marimo run:

import ipyreact_starter
ipyreact_starter.SimpleMap() # the import map version

This uses the version of ipyreact-tsxlib defined via a module

ipyreact_starter.Simple()
manzt commented

To clarify, ipyreact uses some of anywidget's internals and is not itself an anywidget (i.e., it is not the AFM standard which is required by marimo).

marimo's adoption of anywidget is first party, meaning that it does not share any of the underlying jupyter infrastructure that traditional jupyter widgets need. This design decision makes anywidgets more portable than traditional jupyter widgets. Therefore, I would likely not label this issue as a bug with marimo as it is not expected that ipyreact would work.

I’m open to improving shared frontend code reuse between widgets, but it’s not a priority. anywidget’s core value is portability, and added complexity risks making widgets harder to share and reuse, as seen with traditional systems. Such decisions also burden new host platforms like marimo or Panel (who have adopted AFM). For now, I’m fine with some redundant JS, given that widgets often handle megabytes of data or "data apps" run Pyodide, as it ensures better platform support and simplicity. This may change, but I'd like to be explicit about the project’s current core values in relation to the ecosystem and community we are building.

Thanks for clarifying @manzt. I will move this to a discussion since it sounds like marimo would need to support more underlying Jupyter infra that diverges from the anywidget spec (which currently isn't planned)