A platform for community discussion. Free, open, simple.
DEV: add fallback for calling `helper.widget` decorating cooked content when using the Glimmer Post Stream (#32585)
Sérgio Saquetima80017ff6a13
diff --git a/app/assets/javascripts/discourse/app/components/decorated-html.gjs b/app/assets/javascripts/discourse/app/components/decorated-html.gjsindex c134ace98c4..5f3ac52cede 100644--- a/app/assets/javascripts/discourse/app/components/decorated-html.gjs+++ b/app/assets/javascripts/discourse/app/components/decorated-html.gjs@@ -3,6 +3,8 @@ import { untrack } from "@glimmer/validator";import { htmlSafe, isHTMLSafe } from "@ember/template";import { TrackedArray } from "@ember-compat/tracked-built-ins";import helperFn from "discourse/helpers/helper-fn";+import deprecated from "discourse/lib/deprecated";+import { POST_STREAM_DEPRECATION_OPTIONS } from "discourse/lib/plugin-api";const detachedDocument = document.implementation.createHTMLDocument("detached");@@ -90,6 +92,26 @@ class DecorateHtmlHelper {return this.model;}+ // TODO (glimmer-post-stream): remove this when we remove the legacy post stream code+ get widget() {+ deprecated(+ "Accessing `helper.widget` is not supported when using `api.decorateCookedElement` with the Glimmer Post Stream and can yield unexpected results.",+ POST_STREAM_DEPRECATION_OPTIONS+ );++ const attrs = this.model;++ return {+ get attrs() {+ return attrs;+ },+ scheduleRerender() {+ // This is a no-op when using the new glimmer components.+ // the component will rerender automatically when the model changes.+ },+ };+ }+teardown() {this.#renderGlimmerInfos.length = 0;}diff --git a/app/assets/javascripts/discourse/app/lib/plugin-api.gjs b/app/assets/javascripts/discourse/app/lib/plugin-api.gjsindex 39fbc03fdcb..ec8e87ed774 100644--- a/app/assets/javascripts/discourse/app/lib/plugin-api.gjs+++ b/app/assets/javascripts/discourse/app/lib/plugin-api.gjs@@ -193,7 +193,7 @@ const DEPRECATED_POST_STREAM_WIDGETS = ["topic-post-visited-line",];-const POST_STREAM_DEPRECATION_OPTIONS = {+export const POST_STREAM_DEPRECATION_OPTIONS = {since: "v3.5.0.beta1-dev",id: "discourse.post-stream-widget-overrides",// url: "", // TODO (glimmer-post-stream) uncomment when the topic is created on metadiff --git a/plugins/checklist/assets/javascripts/discourse/initializers/checklist.js b/plugins/checklist/assets/javascripts/discourse/initializers/checklist.jsindex c3d846aaa7d..0be612d260d 100644--- a/plugins/checklist/assets/javascripts/discourse/initializers/checklist.js+++ b/plugins/checklist/assets/javascripts/discourse/initializers/checklist.js@@ -1,5 +1,6 @@import { ajax } from "discourse/lib/ajax";import { popupAjaxError } from "discourse/lib/ajax-error";+import { getOwnerWithFallback } from "discourse/lib/get-owner";import { iconHTML } from "discourse/lib/icon-library";import { withPluginApi } from "discourse/lib/plugin-api";import { i18n } from "discourse-i18n";@@ -57,7 +58,11 @@ export function checklistSyntax(elem, postDecorator) {const boxes = [...elem.getElementsByClassName("chcklst-box")];addUlClasses(boxes);- const postWidget = postDecorator?.widget;+ // TODO (glimmer-post-stream): remove this when we remove the legacy post stream code+ const postWidget = getOwnerWithFallback(this).lookup("service:site")+ .useGlimmerPostStream+ ? null+ : postDecorator?.widget;const postModel = postDecorator?.getModel();if (!postModel?.can_edit) {@@ -151,8 +156,11 @@ export function checklistSyntax(elem, postDecorator) {edit_reason: i18n("checklist.edit_reason"),});- postWidget.attrs.isSaving = false;- postWidget.scheduleRerender();+ // TODO (glimmer-post-stream): remove the following code when removing the legacy post stream code+ if (postWidget) {+ postWidget.attrs.isSaving = false;+ postWidget.scheduleRerender();+ }} catch (e) {popupAjaxError(e);} finally {@@ -168,6 +176,6 @@ export default {name: "checklist",initialize() {- withPluginApi("0.1", (api) => initializePlugin(api));+ withPluginApi((api) => initializePlugin(api));},};