Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make serializable data in react-devtools #17233

Merged
merged 4 commits into from
Dec 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ exports[`InspectedElementContext should support complex data types: 1: Inspected
"hooks": null,
"props": {
"array_buffer": {},
"big_int": {},
"date": {},
"fn": {},
"html_element": {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,8 @@ describe('InspectedElementContext', () => {
ReactDOM.render(
<Example
array_buffer={typedArray.buffer}
// eslint-disable-next-line no-undef
big_int={BigInt(123)}
date={new Date()}
fn={exampleFunction}
html_element={div}
Expand Down Expand Up @@ -577,6 +579,7 @@ describe('InspectedElementContext', () => {

const {
array_buffer,
big_int,
date,
fn,
html_element,
Expand All @@ -595,6 +598,10 @@ describe('InspectedElementContext', () => {
expect(array_buffer[meta.name]).toBe('ArrayBuffer');
expect(array_buffer[meta.type]).toBe('array_buffer');

expect(big_int[meta.inspectable]).toBe(false);
expect(big_int[meta.name]).toBe('123');
expect(big_int[meta.type]).toBe('bigint');

expect(date[meta.inspectable]).toBe(false);
expect(date[meta.type]).toBe('date');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ Object {
"hooks": null,
"props": {
"array_buffer": {},
"big_int": {},
"date": {},
"fn": {},
"html_element": {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ describe('InspectedElementContext', () => {
ReactDOM.render(
<Example
array_buffer={typedArray.buffer}
// eslint-disable-next-line no-undef
big_int={BigInt(123)}
date={new Date()}
fn={exampleFunction}
html_element={div}
Expand All @@ -190,6 +192,7 @@ describe('InspectedElementContext', () => {

const {
array_buffer,
big_int,
date,
fn,
html_element,
Expand All @@ -208,6 +211,10 @@ describe('InspectedElementContext', () => {
expect(array_buffer[meta.name]).toBe('ArrayBuffer');
expect(array_buffer[meta.type]).toBe('array_buffer');

expect(big_int[meta.inspectable]).toBe(false);
expect(big_int[meta.name]).toBe('123');
expect(big_int[meta.type]).toBe('bigint');

expect(date[meta.inspectable]).toBe(false);
expect(date[meta.type]).toBe('date');

Expand Down
2 changes: 2 additions & 0 deletions packages/react-devtools-shared/src/devtools/views/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ export function getMetaValueLabel(data: Object): string | null {
case 'date':
case 'symbol':
return name;
case 'bigint':
return `${name}n`;
case 'iterator':
return `${name}(…)`;
case 'array_buffer':
Expand Down
11 changes: 11 additions & 0 deletions packages/react-devtools-shared/src/hydration.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const LEVEL_THRESHOLD = 2;
type PropType =
| 'array'
| 'array_buffer'
| 'bigint'
| 'boolean'
| 'data_view'
| 'date'
Expand Down Expand Up @@ -107,6 +108,8 @@ function getDataType(data: Object): PropType {

const type = typeof data;
switch (type) {
case 'bigint':
return 'bigint';
case 'boolean':
return 'boolean';
case 'function':
Expand Down Expand Up @@ -231,6 +234,14 @@ export function dehydrate(
case 'string':
return data.length <= 500 ? data : data.slice(0, 500) + '...';

case 'bigint':
cleaned.push(path);
return {
inspectable: false,
name: data.toString(),
type,
};

case 'symbol':
cleaned.push(path);
return {
Expand Down