From 48ad326ba442d32415bb4387b9543b7ebad86d9a Mon Sep 17 00:00:00 2001 From: David Taylor Date: Thu, 28 Dec 2023 16:35:06 +0000 Subject: [PATCH] FIX: Handle deprecations correctly in server-side pretty-text (#25059) `window.deprecationWorkflow` does not exist in the server-side pretty-text environment. This commit fixes the check and adds a general spec for deprecations triggered inside pretty-text --- .../discourse-common/addon/lib/deprecated.js | 2 +- spec/lib/pretty_text_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse-common/addon/lib/deprecated.js b/app/assets/javascripts/discourse-common/addon/lib/deprecated.js index bce9aebe86b..cb0e670c88e 100644 --- a/app/assets/javascripts/discourse-common/addon/lib/deprecated.js +++ b/app/assets/javascripts/discourse-common/addon/lib/deprecated.js @@ -52,7 +52,7 @@ export default function deprecated(msg, options = {}) { if ( raiseError || matchedWorkflow?.handler === "throw" || - (!matchedWorkflow && deprecationWorkflow.throwOnUnhandled) + (!matchedWorkflow && deprecationWorkflow?.throwOnUnhandled) ) { throw msg; } diff --git a/spec/lib/pretty_text_spec.rb b/spec/lib/pretty_text_spec.rb index 555ef04d3da..1583ef5fecf 100644 --- a/spec/lib/pretty_text_spec.rb +++ b/spec/lib/pretty_text_spec.rb @@ -2681,4 +2681,16 @@ HTML expect(cooked.strip).to eq(html.strip) end + + it "handles deprecations correctly" do + Rails + .logger + .expects(:warn) + .once + .with("[PrettyText] Deprecation notice: Some deprecation message") + + PrettyText.v8.eval <<~JS + require("discourse-common/lib/deprecated").default("Some deprecation message"); + JS + end end