Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap rendering with try-catch clauses to handle closed widgets #172

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions js/src/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,26 @@ export class WidgetManager extends JupyterLabManager {
const models = await this._build_models();
const tags = document.body.querySelectorAll('script[type="application/vnd.jupyter.widget-view+json"]');
for (let i=0; i!=tags.length; ++i) {
const viewtag = tags[i];
const widgetViewObject = JSON.parse(viewtag.innerHTML);
const { model_id } = widgetViewObject;
const model = models[model_id];
const widgetTag = document.createElement('div');
widgetTag.className = 'widget-subarea';
viewtag.parentElement.insertBefore(widgetTag, viewtag);
const view = await this.display_model(undefined, model, { el : widgetTag });
try {
const viewtag = tags[i];
const widgetViewObject = JSON.parse(viewtag.innerHTML);
const { model_id } = widgetViewObject;
const model = models[model_id];
const widgetTag = document.createElement('div');
widgetTag.className = 'widget-subarea';
viewtag.parentElement.insertBefore(widgetTag, viewtag);
const view = await this.display_model(undefined, model, { el : widgetTag });
} catch (error) {
// Each widget view tag rendering is wrapped with a try-catch statement.
//
// This fixes issues with widget models that are explicitely "closed"
// but are still referred to in a previous cell output.
// Without the try-catch statement, this error interupts the loop and
// prevents the rendering of further cells.
//
// This workaround may not be necessary anymore with templates that make use
// of progressive rendering.
}
}
}

Expand Down