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

[compiler] Enable optional dependencies by default #30838

Merged
merged 1 commit into from
Aug 28, 2024
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 @@ -230,7 +230,7 @@ const EnvironmentConfigSchema = z.object({
* just `props`. With this flag enabled, we'll infer that full path as
* the dependency.
*/
enableOptionalDependencies: z.boolean().default(false),
enableOptionalDependencies: z.boolean().default(true),

/*
* Enable validation of hooks to partially check that the component honors the rules of hooks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import { c as _c } from "react/compiler-runtime";
function Component(props) {
const $ = _c(2);
let t0;
if ($[0] !== props) {
if ($[0] !== props?.items) {
t0 = props?.items?.map?.(render)?.filter(Boolean) ?? [];
$[0] = props;
$[0] = props?.items;
$[1] = t0;
} else {
t0 = $[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ function Component({propA, propB}) {
| ^^^^^^^^^^^^^^^^^
> 14 | }, [propA?.a, propB.x.y]);
| ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected (6:14)

CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected (6:14)
15 | }
16 |
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import { c as _c } from "react/compiler-runtime"; // To preserve the nullthrows
function Component(props) {
const $ = _c(2);
let x;
if ($[0] !== props.a) {
if ($[0] !== props.a?.b) {
x = [];
x.push(props.a?.b);
$[0] = props.a;
$[0] = props.a?.b;
$[1] = x;
} else {
x = $[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ import { c as _c } from "react/compiler-runtime"; // To preserve the nullthrows
function Component(props) {
const $ = _c(2);
let x;
if ($[0] !== props.a) {
if ($[0] !== props.a.b) {
x = [];
x.push(props.a?.b);
x.push(props.a.b.c);
$[0] = props.a;
$[0] = props.a.b;
$[1] = x;
} else {
x = $[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,25 @@ export const FIXTURE_ENTRYPOINT = {
```javascript
import { c as _c } from "react/compiler-runtime";
function Component(props) {
const $ = _c(2);
const $ = _c(5);
let x;
if ($[0] !== props.items) {
if ($[0] !== props.items?.length || $[1] !== props.items?.edges) {
x = [];
x.push(props.items?.length);
x.push(props.items?.edges?.map?.(render)?.filter?.(Boolean) ?? []);
$[0] = props.items;
$[1] = x;
let t0;
if ($[3] !== props.items?.edges) {
t0 = props.items?.edges?.map?.(render)?.filter?.(Boolean) ?? [];
$[3] = props.items?.edges;
$[4] = t0;
} else {
t0 = $[4];
}
x.push(t0);
$[0] = props.items?.length;
$[1] = props.items?.edges;
$[2] = x;
} else {
x = $[1];
x = $[2];
}
return x;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ function HomeDiscoStoreItemTileRating(props) {
const $ = _c(4);
const item = useFragment();
let count;
if ($[0] !== item) {
if ($[0] !== item?.aggregates) {
count = 0;
const aggregates = item?.aggregates || [];
aggregates.forEach((aggregate) => {
count = count + (aggregate.count || 0);
count;
});
$[0] = item;
$[0] = item?.aggregates;
$[1] = count;
} else {
count = $[1];
Expand Down