DEV: Allow RenderGlimmer to be used inside post-cooked-glued widgets (#26675)

In this case, the top-level widget being glued must have a `_postCookedWidget` attribute.
This commit is contained in:
David Taylor 2024-04-18 15:39:29 +01:00 committed by GitHub
parent bfd6a7b86c
commit 5c2ac4fe88
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 1 deletions

View File

@ -178,7 +178,21 @@ export default class RenderGlimmer {
}
get parentMountWidgetComponent() {
return this.widget?._findView() || this._emberView;
if (this._emberView) {
return this._emberView;
}
// Work up parent widgets until we find one with a _emberView
// attribute. `.parentWidget` is the normal way to work up the tree,
// but we use `attrs._postCookedWidget` to handle the special case
// of widgets rendered inside post-cooked.
let widget = this.widget;
while (widget) {
const component = widget._emberView;
if (component) {
return component;
}
widget = widget.parentWidget || widget.attrs._postCookedWidget;
}
}
}

View File

@ -120,6 +120,7 @@ function initializePolls(api) {
groupableUserFields: (pollGroupableUserFields || "")
.split("|")
.filter(Boolean),
_postCookedWidget: helper.widget,
};
const glue = new WidgetGlue("discourse-poll", register, attrs);
glue.appendTo(pollNode);