Some ipywidgets never show up in Positron notebooks

Open
#17,571 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
jupyter, python, typescript

Research direction

The issue points to two paths: output webview sizing after MutationObserver changes, and widget state requests handled by the IPyWidgets service. Start by locating the injected sizing script and the service's request_states and comm_info_request handling, then reproduce each Python example in a notebook. Done means both widgets appear by the time the cell finishes; also check whether the sizing change affects Quarto inline output.

Written by the indexing model from the issue text.

Description

area: notebooks-jupyter bug lang: python

I dug into some empty widget outputs in Positron notebooks while reviewing #17283, and found two separate bugs. Both reproduce on main. 🤖 follows:

1. An Output that gets content after it's displayed stays empty.

# cell 1
import ipywidgets as w
from IPython.display import display

out = w.Output()
display(out)
# cell 2
with out:
    print("written from a later cell")

Cell 1 never shows the text. The text does get rendered into the output's webview, but the webview is about 2px tall and never grows. The script we inject into output webviews to report their height waits for a requestAnimationFrame before sending the size, and in a frame that small the callback never runs. (I checked: a MutationObserver in that frame fires right away, but a requestAnimationFrame callback never does.) So once an output gets measured as nearly empty, nothing after that resizes it.

Widgets that render all at once, like a slider, aren't affected. Output content always renders a little late, since each item round-trips to the main thread to pick a renderer, so it hits this every time.

When I changed the script to send the size straight from the MutationObserver callback, Output content showed up, including the capture-before-display cases from #17283. I haven't checked what else that change touches though; the same script runs in every notebook output webview, and Quarto inline output uses the same size messages.

2. A widget displayed while its cell is still running never renders.

import ipywidgets as w, time
from IPython.display import display

display(w.IntSlider(7))
time.sleep(8)

The same slider without the sleep renders fine.

When the output's webview opens, the widget manager asks the kernel for the widget state with a request_states comm message. The kernel can't answer that while the cell is still running, so it times out after 5 seconds:

Error: RPC timed out after 5 seconds: {"method":"request_states"}

The ipywidgets base manager then falls back to a comm_info_request, which our IPyWidgets service doesn't handle, so the render just hangs for good, even after the cell finishes. This also breaks the "display an Output, then write to it while doing slow work" pattern. I haven't checked whether the console has the same problem.

In both cases the widget should show up, at the latest once the cell finishes.

Dominant language
TypeScript
Stars
4.4k
Forks
207
Avg merge
1d 16h
Merged PRs (30d)
308

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from posit-dev/positron

All issues in posit-dev/positron

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.