Skip to content

Commit

Permalink
Fix: Playground handle bigint in logs (#3169)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaw3d committed Jun 28, 2024
1 parent c341935 commit 309e3e3
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/playground/src/sidebar/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,18 @@ 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__"
if (typeof value === 'bigint') return `BigInt('${value.toString()}')`
return value
},
2
).replace(/"__undefined__"/g, "undefined")

textRep = htmlEscape(textRep)
} else {
Expand Down

0 comments on commit 309e3e3

Please sign in to comment.