Skip to content

Commit dcdf2e1

Browse files
authored
Update _maybeResize() to handle an empty lmWidget container (#143)
1 parent 6719b0e commit dcdf2e1

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [UNRELEASED]
99

10-
10+
* Fixed a bug with multiple altair outputs not working inside a `@shiny.render.ui` decorator. (#140)
1111

1212
## [0.3.1] - 2024-03-01
1313

js/src/output.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,29 +113,32 @@ class IPyWidgetOutput extends Shiny.OutputBinding {
113113
this._maybeResize(lmWidget);
114114
}
115115
_maybeResize(lmWidget: HTMLElement): void {
116-
const impl = lmWidget.children[0];
117-
if (impl.children.length > 0) {
118-
return this._doResize(impl);
116+
if (this._hasImplementation(lmWidget)) {
117+
return this._doResize();
119118
}
120119

121120
// Some widget implementation (e.g., ipyleaflet, pydeck) won't actually
122121
// have rendered to the DOM at this point, so wait until they do
123122
const mo = new MutationObserver((mutations) => {
124-
if (impl.children.length > 0) {
123+
if (this._hasImplementation(lmWidget)) {
125124
mo.disconnect();
126-
this._doResize(impl);
125+
this._doResize();
127126
}
128127
});
129128

130-
mo.observe(impl, {childList: true});
129+
mo.observe(lmWidget, {childList: true});
131130
}
132-
_doResize(impl: Element): void {
131+
_doResize(): void {
133132
// Trigger resize event to force layout (setTimeout() is needed for altair)
134133
// TODO: debounce this call?
135134
setTimeout(() => {
136135
window.dispatchEvent(new Event('resize'))
137136
}, 0);
138137
}
138+
_hasImplementation(lmWidget: HTMLElement): boolean {
139+
const impl = lmWidget.children[0];
140+
return impl && impl.children.length > 0;
141+
}
139142
}
140143

141144
Shiny.outputBindings.register(new IPyWidgetOutput(), "shiny.IPyWidgetOutput");

shinywidgets/static/output.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)