From 5c7f6e5301fdbb4bb2a3c54a9251d500005a7f22 Mon Sep 17 00:00:00 2001 From: alvarosabu Date: Wed, 4 Sep 2024 11:39:19 +0200 Subject: [PATCH] fix: add option to supress deprecation warning --- playground/vanilla/src/main.ts | 5 ++--- src/richTextResolver.ts | 14 ++++++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/playground/vanilla/src/main.ts b/playground/vanilla/src/main.ts index f1c12133..ceb36e74 100644 --- a/playground/vanilla/src/main.ts +++ b/playground/vanilla/src/main.ts @@ -33,9 +33,8 @@ try { ], } - const html = resolver.render(paragraph) - - console.log(Storyblok.cacheVersions()) + const html = resolver.render(paragraph, {}, false) + document.querySelector('#app')!.innerHTML = `
diff --git a/src/richTextResolver.ts b/src/richTextResolver.ts
index 65b92eb1..e3eb226c 100644
--- a/src/richTextResolver.ts
+++ b/src/richTextResolver.ts
@@ -58,6 +58,8 @@ interface ISbFunction {
   (...args: T): R
 }
 
+let hasWarnedAboutDeprecation = false; 
+
 class RichTextResolver {
   private marks: ISbNode
   private nodes: ISbNode
@@ -81,11 +83,15 @@ class RichTextResolver {
 
   public render(
     data?: ISbRichtext,
-    options: RenderOptions = { optimizeImages: false }
+    options: RenderOptions = { optimizeImages: false },
+    deprecationWarning = true
   ) {
-    console.warn(
-      "Warning ⚠️: The RichTextResolver class is deprecated and will be removed in the next major release. Please use the `@storyblok/richtext` package instead. https://github.com/storyblok/richtext/"
-    );
+    if(!hasWarnedAboutDeprecation && deprecationWarning) {
+      console.warn(
+        "Warning ⚠️: The RichTextResolver class is deprecated and will be removed in the next major release. Please use the `@storyblok/richtext` package instead. https://github.com/storyblok/richtext/"
+      );
+      hasWarnedAboutDeprecation = true
+    }
     if (data && data.content && Array.isArray(data.content)) {
       let html = ''