Skip to content
Open
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 @@ -583,6 +583,7 @@ describe('InspectedElement', () => {
boolean_true={true}
infinity={Infinity}
minus_infinity={-Infinity}
minus_zero={-0}
integer_zero={0}
integer_one={1}
float={1.23}
Expand All @@ -606,6 +607,7 @@ describe('InspectedElement', () => {
"integer_one": 1,
"integer_zero": 0,
"minus_infinity": -Infinity,
"minus_zero": -0,
"nan": NaN,
"string": "abc",
"string_empty": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ describe('InspectedElementContext', () => {
boolean_true: true,
infinity: Infinity,
minus_infinity: -Infinity,
minus_zero: -0,
integer_zero: 0,
integer_one: 1,
float: 1.23,
Expand Down Expand Up @@ -130,6 +131,7 @@ describe('InspectedElementContext', () => {
"integer_one": 1,
"integer_zero": 0,
"minus_infinity": -Infinity,
"minus_zero": -0,
"nan": NaN,
"string": "abc",
"string_empty": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@ describe('useEditableValue', () => {
expect(state.isValid).toBe(true);
});

it('should preserve -0 as an editable value', () => {
let state;

function Example({value = -0}) {
const tuple = useEditableValue(value);
state = tuple[0];
return null;
}

act(() => render(<Example />));

expect(state.editableValue).toEqual('-0');
expect(Object.is(state.externalValue, -0)).toBe(true);
expect(Object.is(state.parsedValue, -0)).toBe(true);
expect(state.hasPendingChanges).toBe(false);
expect(state.isValid).toBe(true);
});

it('should override editable state when external props are updated', () => {
let state;

Expand Down
4 changes: 4 additions & 0 deletions packages/react-devtools-shared/src/devtools/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ export function smartParse(value: any): any | void | number {
return Infinity;
case '-Infinity':
return -Infinity;
case '-0':
return -0;
case 'NaN':
return NaN;
case 'undefined':
Expand All @@ -252,6 +254,8 @@ export function smartStringify(value: any): string {
return 'NaN';
} else if (!Number.isFinite(value)) {
return value > 0 ? 'Infinity' : '-Infinity';
} else if (Object.is(value, -0)) {
return '-0';
}
} else if (value === undefined) {
return 'undefined';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ export default function KeyValue({
displayValue = 'undefined';
} else if (isNaN(value)) {
displayValue = 'NaN';
} else if (Object.is(value, -0)) {
displayValue = '-0';
}

let shouldDisplayValueAsLink = false;
Expand Down
3 changes: 3 additions & 0 deletions packages/react-devtools-shared/src/hydration.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ export function dehydrate(
}
case 'infinity':
case '-infinity':
case '-0':
case 'nan':
case 'undefined':
// Some values are lossy when sent through a WebSocket.
Expand Down Expand Up @@ -707,6 +708,8 @@ export function hydrate(
parent[last] = Infinity;
} else if (value.type === '-infinity') {
parent[last] = -Infinity;
} else if (value.type === '-0') {
parent[last] = -0;
} else if (value.type === 'nan') {
parent[last] = NaN;
} else if (value.type === 'undefined') {
Expand Down
7 changes: 7 additions & 0 deletions packages/react-devtools-shared/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ export type DataType =
| 'html_element'
| 'infinity'
| '-infinity'
| '-0'
| 'iterator'
| 'opaque_iterator'
| 'nan'
Expand Down Expand Up @@ -767,6 +768,8 @@ export function getDataType(data: Object): DataType {
return 'nan';
} else if (!Number.isFinite(data)) {
return data > 0 ? 'infinity' : '-infinity';
} else if (Object.is(data, -0)) {
return '-0';
} else {
return 'number';
}
Expand Down Expand Up @@ -1221,9 +1224,13 @@ export function formatDataForPreview(
case 'number':
case 'infinity':
case '-infinity':
case '-0':
case 'nan':
case 'null':
case 'undefined':
if (Object.is(data, -0)) {
return '-0';
}
return String(data);
default:
try {
Expand Down