(core) Fixing bug with collapsed custom widget.

Summary:
Fix for a bug. Custom widget when collapsed and expanded was disconnecting from
Grist, as WidgetFrame was disposed to early.

Test Plan: Added new

Reviewers: georgegevoian

Reviewed By: georgegevoian

Differential Revision: https://phab.getgrist.com/D4109
This commit is contained in:
Jarosław Sadziński
2023-11-06 16:28:14 +01:00
parent 3210eee24f
commit 9262e1f1ef
4 changed files with 69 additions and 16 deletions

View File

@@ -242,7 +242,7 @@ export class CustomView extends Disposable {
const {baseUrl, access, showAfterReady, widgetId, pluginId} = options;
const documentSettings = this.gristDoc.docData.docSettings();
const readonly = this.gristDoc.isReadonly.get();
return grains.create(WidgetFrame, {
const frame = WidgetFrame.create(null, {
url: baseUrl || this.getEmptyWidgetPage(),
widgetId,
pluginId,
@@ -304,6 +304,12 @@ export class CustomView extends Disposable {
gristDoc: this.gristDoc,
});
// Can't use dom.create() because it seems buggy in this context. This dom will be detached
// and attached several times, and dom.create() doesn't seem to handle that well as it returns an
// array of nodes (comment, node, comment) and it somehow breaks the dispose order. Collapsed widgets
// relay on a correct order of dispose, and are detaching nodes just before they are disposed, so if
// the order is wrong, the node is disposed without being detached first.
return grains.update(frame.buildDom(), dom.autoDispose(frame));
}
}

View File

@@ -185,17 +185,17 @@ export class WidgetFrame extends DisposableWithEvents {
public buildDom() {
const onElem = this._options.onElem ?? ((el: HTMLIFrameElement) => el);
return onElem(
(this._iframe = dom(
'iframe',
dom.style('visibility', use => use(this._visible) ? 'visible' : 'hidden'),
dom.cls('clipboard_focus'),
dom.cls('custom_view'),
dom.attr('src', use => this._getUrl(use(this._widget))),
hooks.iframeAttributes,
testId('ready', this._readyCalled),
))
this._iframe = dom(
'iframe',
dom.style('visibility', use => use(this._visible) ? 'visible' : 'hidden'),
dom.cls('clipboard_focus'),
dom.cls('custom_view'),
dom.attr('src', use => this._getUrl(use(this._widget))),
hooks.iframeAttributes,
testId('ready', this._readyCalled),
self => void onElem(self),
);
return this._iframe;
}
private _getUrl(widget: ICustomWidget|null): string {