Skip to content

Commit 3b64afb

Browse files
markrickertfrankcalise
andauthoredOct 30, 2024··
fix: BigInts on hermes android were crashing during serialization for reactotron (#1498 by @markrickert)
## Please verify the following: - [x] `yarn build-and-test:local` passes - [x] I have added tests for any new features, if relevant - [x] `README.md` (or relevant documentation) has been updated with your changes ## Describe your PR I though I had fixed this but we got more reports from the community that it was still broken on android. I added a few new buttons to the example app and was able to reproduce the crash on my android emulator on expo 50 / rn 0.73.6. With these changes, bigints show up properly in the reactotron app. Closes #1436 ![33A78A6F-C83B-4CA6-BDA2-8F3F6E1A5B16-75409-00059A133DB30F84](https://github.com/user-attachments/assets/43fc45a2-4194-4567-9d5d-8cb92ff0d2bf) Co-authored-by: Frank Calise <fcalise@gmail.com>
1 parent 73bc5bc commit 3b64afb

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed
 

‎apps/example-app/app/screens/LoggingScreen.tsx

+25
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,31 @@ export const LoggingScreen: React.FC<LoggingScreenProps> = function LoggingScree
7979
console.error("This is a console.error()", { with: "possible data" })
8080
}}
8181
/>
82+
<Button
83+
text="console.log a BigInt"
84+
textStyle={$darkText}
85+
style={$button}
86+
onPress={() => {
87+
console.log(BigInt(0))
88+
}}
89+
/>
90+
<Button
91+
text="console.log a JSON Serialized BigInt"
92+
textStyle={$darkText}
93+
style={$button}
94+
onPress={() => {
95+
console.log(
96+
JSON.stringify({
97+
int: 12,
98+
string: "hello",
99+
function: function () {
100+
console.log("HELLO!")
101+
},
102+
bigInt: BigInt(0),
103+
})
104+
)
105+
}}
106+
/>
82107
</View>
83108
<View style={$topContainer}>
84109
<Text style={$text} tx="loggingsScreen.subtitle" />

‎apps/example-app/babel.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports = function (api) {
77
return {
88
assumptions: {
99
setPublicClassFields: true,
10+
privateFieldsAsSymbols: true,
1011
},
1112
presets: ["babel-preset-expo"],
1213
env: {

‎lib/reactotron-core-client/src/serialize.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,21 @@ const NEGATIVE_INFINITY = "~~~ -Infinity ~~~"
1717

1818
/**
1919
* Fix BigInt serialization
20-
* BigInts are not supported by JSON.stringify. This is a workaround.
20+
* BigInts are not supported by JSON.stringify in Hermes android.
21+
* This is a workaround.
2122
* https://github.com/GoogleChromeLabs/jsbi/issues/30#issuecomment-953187833
23+
* https://github.com/infinitered/reactotron/issues/1436
2224
*/
2325
declare global {
2426
interface BigInt {
2527
toJSON(): string
2628
}
2729
}
28-
// eslint-disable-next-line no-extend-native
29-
BigInt.prototype.toJSON = function () {
30-
return this.toString()
30+
if (typeof BigInt !== "undefined") {
31+
// eslint-disable-next-line no-extend-native
32+
BigInt.prototype.toJSON = function () {
33+
return this.toString()
34+
}
3135
}
3236

3337
/**
@@ -89,6 +93,8 @@ function serialize(source: any, proxyHack = false) {
8993
return value
9094
case "number":
9195
return value
96+
case "bigint":
97+
return value.toString()
9298
case "function":
9399
return getFunctionName(value)
94100
}

0 commit comments

Comments
 (0)
Please sign in to comment.