Skip to content

Commit 309e3e3

Browse files
authored
Fix: Playground handle bigint in logs (#3169)
1 parent c341935 commit 309e3e3

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

packages/playground/src/sidebar/runtime.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,18 @@ function rewireLoggingToElement(
218218
const nameWithoutObject = name && name === "Object" ? "" : htmlEscape(name)
219219
const prefix = nameWithoutObject ? `${nameWithoutObject}: ` : ""
220220

221-
// 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
222221
textRep =
223222
prefix +
224-
JSON.stringify(arg, (_, value) => (value === undefined ? "__undefined__" : value), 2).replace(
225-
/"__undefined__"/g,
226-
"undefined"
227-
)
223+
JSON.stringify(
224+
arg,
225+
(_, value) => {
226+
// 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
227+
if (value === undefined) return "__undefined__"
228+
if (typeof value === 'bigint') return `BigInt('${value.toString()}')`
229+
return value
230+
},
231+
2
232+
).replace(/"__undefined__"/g, "undefined")
228233

229234
textRep = htmlEscape(textRep)
230235
} else {

0 commit comments

Comments
 (0)