From 653642f3695f0ac8cb61d64c526d818845c3fb23 Mon Sep 17 00:00:00 2001
From: Christian Bromann <git@bromann.dev>
Date: Wed, 18 Dec 2024 13:59:25 -0800
Subject: [PATCH] fix(react): hide SSR rendering error (#573)

---
 packages/react/src/react/ssr.tsx | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/packages/react/src/react/ssr.tsx b/packages/react/src/react/ssr.tsx
index c90c1186..02c1fd2e 100644
--- a/packages/react/src/react/ssr.tsx
+++ b/packages/react/src/react/ssr.tsx
@@ -145,12 +145,14 @@ export const createComponentForServerSideRendering = <I extends HTMLElement, E e
       /**
        * if rendering the light DOM fails, we log a warning and continue to render the component
        */
-      const error = err instanceof Error ? err : new Error('Unknown error');
-      console.warn(
-        `${LOG_PREFIX} Failed to serialize light DOM for ${toSerialize.slice(0, -1)} />: ${
-          error.message
-        } - this may impact the hydration of the component`
-      );
+      if (process.env.STENCIL_SSR_DEBUG) {
+        const error = err instanceof Error ? err : new Error('Unknown error');
+        console.warn(
+          `${LOG_PREFIX} Failed to serialize light DOM for ${toSerialize.slice(0, -1)} />: ${
+            error.message
+          } - this may impact the hydration of the component`
+        );
+      }
     }
 
     const toSerializeWithChildren = `${toSerialize}${serializedChildren}</${options.tagName}>`;