Skip to content

Commit 5932fb3

Browse files
committed
fix: add bigint data type in hydration
1 parent ea44d1f commit 5932fb3

File tree

4 files changed

+14
-67
lines changed

4 files changed

+14
-67
lines changed

packages/react-devtools-shared/src/__tests__/backend/utils-test.js

Lines changed: 0 additions & 43 deletions
This file was deleted.

packages/react-devtools-shared/src/backend/utils.js

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,6 @@ import {dehydrate} from '../hydration';
1111

1212
import type {DehydratedData} from 'react-devtools-shared/src/devtools/views/Components/types';
1313

14-
export function getSerializableData(data: any) {
15-
if (data === null) {
16-
return data;
17-
}
18-
// $FlowFixMe
19-
if (typeof data === 'bigint') {
20-
return data.toString() + 'n';
21-
}
22-
if (Array.isArray(data)) {
23-
return data.reduce(function(acc, val) {
24-
acc.push(getSerializableData(val));
25-
return acc;
26-
}, []);
27-
}
28-
if (typeof data === 'object') {
29-
return Object.keys(data).reduce(function(acc, key) {
30-
acc[key] = getSerializableData(data[key]);
31-
return acc;
32-
}, {});
33-
}
34-
return data;
35-
}
36-
3714
export function cleanForBridge(
3815
data: Object | null,
3916
isPathWhitelisted: (path: Array<string | number>) => boolean,
@@ -49,7 +26,7 @@ export function cleanForBridge(
4926
path,
5027
isPathWhitelisted,
5128
);
52-
29+
console.log(cleanedData);
5330
return {
5431
data: cleanedData,
5532
cleaned: cleanedPaths,

packages/react-devtools-shared/src/devtools/views/utils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ export function getMetaValueLabel(data: Object): string | null {
107107
case 'date':
108108
case 'symbol':
109109
return name;
110+
case 'bigint':
111+
return `${name}n`;
110112
case 'iterator':
111113
return `${name}(…)`;
112114
case 'array_buffer':

packages/react-devtools-shared/src/hydration.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const LEVEL_THRESHOLD = 2;
6969
type PropType =
7070
| 'array'
7171
| 'array_buffer'
72+
| 'bigint'
7273
| 'boolean'
7374
| 'data_view'
7475
| 'date'
@@ -107,6 +108,8 @@ function getDataType(data: Object): PropType {
107108

108109
const type = typeof data;
109110
switch (type) {
111+
case 'bigint':
112+
return 'bigint';
110113
case 'boolean':
111114
return 'boolean';
112115
case 'function':
@@ -231,6 +234,14 @@ export function dehydrate(
231234
case 'string':
232235
return data.length <= 500 ? data : data.slice(0, 500) + '...';
233236

237+
case 'bigint':
238+
cleaned.push(path);
239+
return {
240+
inspectable: false,
241+
name: data.toString(),
242+
type,
243+
};
244+
234245
case 'symbol':
235246
cleaned.push(path);
236247
return {

0 commit comments

Comments
 (0)