From 7edb74eb255d5e46c7f28cf5ca691440400e3b82 Mon Sep 17 00:00:00 2001 From: Luka Jeran Date: Fri, 28 Jun 2024 04:13:26 +0000 Subject: [PATCH 1/2] chore: refactor Playground handling undefined in logs --- packages/playground/src/sidebar/runtime.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/playground/src/sidebar/runtime.ts b/packages/playground/src/sidebar/runtime.ts index 75b454242d42..cfa921199a67 100644 --- a/packages/playground/src/sidebar/runtime.ts +++ b/packages/playground/src/sidebar/runtime.ts @@ -218,13 +218,17 @@ function rewireLoggingToElement( const nameWithoutObject = name && name === "Object" ? "" : htmlEscape(name) const prefix = nameWithoutObject ? `${nameWithoutObject}: ` : "" - // JSON.stringify omits any keys with a value of undefined. To get around this, we replace undefined with the text __undefined__ and then do a global replace using regex back to keyword undefined textRep = prefix + - JSON.stringify(arg, (_, value) => (value === undefined ? "__undefined__" : value), 2).replace( - /"__undefined__"/g, - "undefined" - ) + JSON.stringify( + arg, + (_, value) => { + // JSON.stringify omits any keys with a value of undefined. To get around this, we replace undefined with the text __undefined__ and then do a global replace using regex back to keyword undefined + if (value === undefined) return "__undefined__" + return value + }, + 2 + ).replace(/"__undefined__"/g, "undefined") textRep = htmlEscape(textRep) } else { From 5e6af093dfd3fa795fade52f57575c89c8b63347 Mon Sep 17 00:00:00 2001 From: Luka Jeran Date: Fri, 28 Jun 2024 04:16:48 +0000 Subject: [PATCH 2/2] Fix: Playground handle bigint in logs --- packages/playground/src/sidebar/runtime.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/playground/src/sidebar/runtime.ts b/packages/playground/src/sidebar/runtime.ts index cfa921199a67..bf79d3f2c65b 100644 --- a/packages/playground/src/sidebar/runtime.ts +++ b/packages/playground/src/sidebar/runtime.ts @@ -225,6 +225,7 @@ function rewireLoggingToElement( (_, value) => { // JSON.stringify omits any keys with a value of undefined. To get around this, we replace undefined with the text __undefined__ and then do a global replace using regex back to keyword undefined if (value === undefined) return "__undefined__" + if (typeof value === 'bigint') return `BigInt('${value.toString()}')` return value }, 2