marimo-team / marimo

A reactive notebook for Python — run reproducible experiments, execute as a script, deploy as an app, and version with git.
https://marimo.io
Apache License 2.0
7.95k stars 278 forks source link

ipyreact doesn't work properly #2904

Open paddymul opened 2 days ago

paddymul commented 2 days ago

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()