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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -577,14 +577,21 @@ function codegenReactiveScope(

for (const dep of [...scope.dependencies].sort(compareScopeDependency)) {
const index = cx.nextCacheIndex;
const comparison = t.binaryExpression(
'!==',
t.memberExpression(
t.identifier(cx.synthesizeName('$')),
t.numericLiteral(index),
true,
// Use Object.is() to correctly handle NaN and -0 comparisons,
// consistent with React's runtime hook dependency comparison.
const comparison = t.unaryExpression(
'!',
t.callExpression(
t.memberExpression(t.identifier('Object'), t.identifier('is')),
[
t.memberExpression(
t.identifier(cx.synthesizeName('$')),
t.numericLiteral(index),
true,
),
codegenDependency(cx, dep),
],
),
codegenDependency(cx, dep),
);
changeExpressions.push(comparison);
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { c as _c } from "react/compiler-runtime";
function component(a) {
const $ = _c(2);
let x;
if ($[0] !== a) {
if (!Object.is($[0], a)) {
x = { a };
const y = {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { c as _c } from "react/compiler-runtime";
function foo(cond) {
const $ = _c(2);
let a;
if ($[0] !== cond) {
if (!Object.is($[0], cond)) {
a = {};
let b = {};
let c = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function Component(t0) {
const $ = _c(2);
const { prop } = t0;
let t1;
if ($[0] !== prop) {
if (!Object.is($[0], prop)) {
const obj = shallowCopy(prop);
const aliasedObj = identity(obj);
const getId = () => obj.id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ function Component(t0) {
const $ = _c(2);
const { prop } = t0;
let t1;
if ($[0] !== prop) {
if (!Object.is($[0], prop)) {
const obj = shallowCopy(prop);
const aliasedObj = identity(obj);
const id = [obj.id];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function useFoo(cond) {
const $ = _c(3);
let s;
let t0;
if ($[0] !== cond) {
if (!Object.is($[0], cond)) {
t0 = Symbol.for("react.early_return_sentinel");
bb0: {
if (cond) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { getNull } from "shared-runtime";
function Component(props) {
const $ = _c(2);
let items;
if ($[0] !== props.a) {
if (!Object.is($[0], props.a)) {
items = getNull() ?? [];

items.push(props.a);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function useFoo(t0) {
const { cond1, cond2 } = t0;
let s;
let t1;
if ($[0] !== cond1 || $[1] !== cond2) {
if (!Object.is($[0], cond1) || !Object.is($[1], cond2)) {
t1 = Symbol.for("react.early_return_sentinel");
bb0: {
if (cond1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function useFoo(t0) {
t1 = $[0];
}
let items = t1;
if ($[1] !== cond) {
if (!Object.is($[1], cond)) {
bb0: {
if (cond) {
items = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function useFoo(t0) {
const $ = _c(3);
const { cond, value } = t0;
let items;
if ($[0] !== cond || $[1] !== value) {
if (!Object.is($[0], cond) || !Object.is($[1], value)) {
bb0: {
items = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function useFoo(t0) {
const $ = _c(2);
const { value } = t0;
let items;
if ($[0] !== value) {
if (!Object.is($[0], value)) {
try {
items = [];
arrayPush(items, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function Foo(t0) {
const $ = _c(3);
const { cond1, cond2 } = t0;
let t1;
if ($[0] !== cond1 || $[1] !== cond2) {
if (!Object.is($[0], cond1) || !Object.is($[1], cond2)) {
const arr = makeArray({ a: 2 }, 2, []);
t1 = cond1 ? (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ function Foo() {
const $ = _c(4);
const data = useFragment();
let t0;
if ($[0] !== data) {
if (!Object.is($[0], data)) {
t0 = data?.toString() || "";
$[0] = data;
$[1] = t0;
} else {
t0 = $[1];
}
let t1;
if ($[2] !== t0) {
if (!Object.is($[2], t0)) {
t1 = [t0];
$[2] = t0;
$[3] = t1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ import { identity, mutate, setProperty } from "shared-runtime";
function AllocatingPrimitiveAsDepNested(props) {
const $ = _c(5);
let t0;
if ($[0] !== props.a || $[1] !== props.b) {
if (!Object.is($[0], props.a) || !Object.is($[1], props.b)) {
const x = {};
mutate(x);
const t1 = identity(props.b) + 1;
let t2;
if ($[3] !== t1) {
if (!Object.is($[3], t1)) {
t2 = identity(t1);
$[3] = t1;
$[4] = t2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function AllocatingPrimitiveAsDep(props) {
const $ = _c(2);
const t0 = bar(props).b + 1;
let t1;
if ($[0] !== t0) {
if (!Object.is($[0], t0)) {
t1 = foo(t0);
$[0] = t0;
$[1] = t1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function Component() {

const t4 = String(state);
let t5;
if ($[4] !== t4) {
if (!Object.is($[4], t4)) {
t5 = <div>{t4}</div>;
$[4] = t4;
$[5] = t5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function Component() {

const t4 = String(state);
let t5;
if ($[4] !== t4) {
if (!Object.is($[4], t4)) {
t5 = <div>{t4}</div>;
$[4] = t4;
$[5] = t5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function Component() {

const t4 = String(state);
let t5;
if ($[4] !== t4) {
if (!Object.is($[4], t4)) {
t5 = <div>{t4}</div>;
$[4] = t4;
$[5] = t5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function Component() {

const t3 = String(state);
let t4;
if ($[3] !== t3) {
if (!Object.is($[3], t3)) {
t4 = <div>{t3}</div>;
$[3] = t3;
$[4] = t4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function Component(t0) {
const $ = _c(4);
const { value } = t0;
let t1;
if ($[0] !== value) {
if (!Object.is($[0], value)) {
t1 = () => {
someGlobal.value = value;
};
Expand All @@ -53,7 +53,7 @@ function Component(t0) {
}
const onClick = t1;
let t2;
if ($[2] !== onClick) {
if (!Object.is($[2], onClick)) {
t2 = <div onClick={onClick}>{someGlobal.value}</div>;
$[2] = onClick;
$[3] = t2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function Component() {

const t3 = String(state);
let t4;
if ($[3] !== t3) {
if (!Object.is($[3], t3)) {
t4 = <div>{t3}</div>;
$[3] = t3;
$[4] = t4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function Component(props) {
const T0 = Foo;
const t0 = props.render({ ref });
let t1;
if ($[0] !== T0 || $[1] !== t0) {
if (!Object.is($[0], T0) || !Object.is($[1], t0)) {
t1 = <T0>{t0}</T0>;
$[0] = T0;
$[1] = t0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ function Component(props) {
const $ = _c(4);
const ref = useRef(null);
let t0;
if ($[0] !== props.render) {
if (!Object.is($[0], props.render)) {
t0 = props.render(ref);
$[0] = props.render;
$[1] = t0;
} else {
t0 = $[1];
}
let t1;
if ($[2] !== t0) {
if (!Object.is($[2], t0)) {
t1 = <Foo>{t0}</Foo>;
$[2] = t0;
$[3] = t1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function Component() {

const t5 = String(state);
let t6;
if ($[5] !== t5) {
if (!Object.is($[5], t5)) {
t6 = <Child key={t5} ref={ref} />;
$[5] = t5;
$[6] = t6;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function Component() {

const t4 = String(state);
let t5;
if ($[4] !== t4) {
if (!Object.is($[4], t4)) {
t5 = <Child key={t4} ref={ref} />;
$[4] = t4;
$[5] = t5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function Component() {

const t3 = String(state);
let t4;
if ($[3] !== t3) {
if (!Object.is($[3], t3)) {
t4 = <Child key={t3} ref={ref} />;
$[3] = t3;
$[4] = t4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ function Component(t0) {
const $ = _c(6);
const { a, b, c } = t0;
let t1;
if ($[0] !== a || $[1] !== b || $[2] !== c) {
if (!Object.is($[0], a) || !Object.is($[1], b) || !Object.is($[2], c)) {
const x = [a];
let t2;
if ($[4] !== b) {
if (!Object.is($[4], b)) {
t2 = [null, b];
$[4] = b;
$[5] = t2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { c as _c } from "react/compiler-runtime";
function Component(props) {
const $ = _c(5);
let t0;
if ($[0] !== props.x) {
if (!Object.is($[0], props.x)) {
t0 = foo(props.x);
$[0] = props.x;
$[1] = t0;
Expand All @@ -30,7 +30,7 @@ function Component(props) {
}
const x = t0;
let t1;
if ($[2] !== props || $[3] !== x) {
if (!Object.is($[2], props) || !Object.is($[3], x)) {
const fn = function () {
const arr = [...bar(props)];
return arr.at(x);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ import { c as _c } from "react/compiler-runtime"; // arrayInstance.at should hav
function ArrayAtTest(props) {
const $ = _c(9);
let t0;
if ($[0] !== props.x) {
if (!Object.is($[0], props.x)) {
t0 = foo(props.x);
$[0] = props.x;
$[1] = t0;
} else {
t0 = $[1];
}
let t1;
if ($[2] !== t0) {
if (!Object.is($[2], t0)) {
t1 = [t0];
$[2] = t0;
$[3] = t1;
Expand All @@ -41,9 +41,9 @@ function ArrayAtTest(props) {
}
const arr = t1;
let t2;
if ($[4] !== arr || $[5] !== props.y) {
if (!Object.is($[4], arr) || !Object.is($[5], props.y)) {
let t3;
if ($[7] !== props.y) {
if (!Object.is($[7], props.y)) {
t3 = bar(props.y);
$[7] = props.y;
$[8] = t3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { c as _c } from "react/compiler-runtime"; // x's mutable range should ex
function Component(props) {
const $ = _c(2);
let x;
if ($[0] !== props.b) {
if (!Object.is($[0], props.b)) {
x = [42, {}];
const idx = foo(props.b);
const y = x.at(idx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function Foo(t0) {
const $ = _c(2);
const { inputNum } = t0;
let arr2;
if ($[0] !== inputNum) {
if (!Object.is($[0], inputNum)) {
const arr1 = [{ a: 1 }, {}];
arr2 = arr1.concat([1, inputNum]);
mutate(arr2[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { c as _c } from "react/compiler-runtime";
function Component(props) {
const $ = _c(3);
let t0;
if ($[0] !== props.bar || $[1] !== props.foo) {
if (!Object.is($[0], props.bar) || !Object.is($[1], props.foo)) {
t0 = [0, ...props.foo, null, ...props.bar, "z"];
$[0] = props.bar;
$[1] = props.foo;
Expand Down
Loading