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
This commit is contained in:
David Taylor 2023-12-28 16:35:06 +00:00 committed by GitHub
parent 8e58c6dd93
commit 48ad326ba4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -52,7 +52,7 @@ export default function deprecated(msg, options = {}) {
if (
raiseError ||
matchedWorkflow?.handler === "throw" ||
(!matchedWorkflow && deprecationWorkflow.throwOnUnhandled)
(!matchedWorkflow && deprecationWorkflow?.throwOnUnhandled)
) {
throw msg;
}

View File

@ -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