Skip to content

[pull] main from facebook:main #179

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

Merged
merged 3 commits into from
Jul 16, 2025
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
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ module.exports = {
{
files: ['packages/react-server-dom-turbopack/**/*.js'],
globals: {
__turbopack_load__: 'readonly',
__turbopack_load_by_url__: 'readonly',
__turbopack_require__: 'readonly',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3001,6 +3001,8 @@ function isReorderableExpression(
}
}
}
case 'TSAsExpression':
case 'TSNonNullExpression':
case 'TypeCastExpression': {
return isReorderableExpression(
builder,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

## Input

```javascript
type Status = 'pending' | 'success' | 'error';

const StatusIndicator = ({status}: {status: Status}) => {
return <div className={`status-${status}`}>Status: {status}</div>;
};

const Component = ({status = 'pending' as Status}) => {
return <StatusIndicator status={status} />;
};

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{status: 'success'}],
};

```

## Code

```javascript
import { c as _c } from "react/compiler-runtime";
type Status = "pending" | "success" | "error";

const StatusIndicator = (t0) => {
const $ = _c(3);
const { status } = t0;
const t1 = `status-${status}`;
let t2;
if ($[0] !== status || $[1] !== t1) {
t2 = <div className={t1}>Status: {status}</div>;
$[0] = status;
$[1] = t1;
$[2] = t2;
} else {
t2 = $[2];
}
return t2;
};

const Component = (t0) => {
const $ = _c(2);
const { status: t1 } = t0;
const status = t1 === undefined ? ("pending" as Status) : t1;
let t2;
if ($[0] !== status) {
t2 = <StatusIndicator status={status} />;
$[0] = status;
$[1] = t2;
} else {
t2 = $[1];
}
return t2;
};

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ status: "success" }],
};

```

### Eval output
(kind: ok) <div class="status-success">Status: success</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
type Status = 'pending' | 'success' | 'error';

const StatusIndicator = ({status}: {status: Status}) => {
return <div className={`status-${status}`}>Status: {status}</div>;
};

const Component = ({status = 'pending' as Status}) => {
return <StatusIndicator status={status} />;
};

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{status: 'success'}],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

## Input

```javascript
const THEME_MAP: ReadonlyMap<string, string> = new Map([
['default', 'light'],
['dark', 'dark'],
]);

export const Component = ({theme = THEME_MAP.get('default')!}) => {
return <div className={`theme-${theme}`}>User preferences</div>;
};

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{status: 'success'}],
};

```

## Code

```javascript
import { c as _c } from "react/compiler-runtime";
const THEME_MAP: ReadonlyMap<string, string> = new Map([
["default", "light"],
["dark", "dark"],
]);

export const Component = (t0) => {
const $ = _c(2);
const { theme: t1 } = t0;
const theme = t1 === undefined ? THEME_MAP.get("default") : t1;
const t2 = `theme-${theme}`;
let t3;
if ($[0] !== t2) {
t3 = <div className={t2}>User preferences</div>;
$[0] = t2;
$[1] = t3;
} else {
t3 = $[1];
}
return t3;
};

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ status: "success" }],
};

```

### Eval output
(kind: ok) <div class="theme-light">User preferences</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const THEME_MAP: ReadonlyMap<string, string> = new Map([
['default', 'light'],
['dark', 'dark'],
]);

export const Component = ({theme = THEME_MAP.get('default')!}) => {
return <div className={`theme-${theme}`}>User preferences</div>;
};

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{status: 'success'}],
};
20 changes: 20 additions & 0 deletions packages/react-client/src/ReactFlightClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,26 @@ function waitForReference<T>(
map: (response: Response, model: any, parentObject: Object, key: string) => T,
path: Array<string>,
): T {
if (
__DEV__ &&
// TODO: This should check for the existence of the "readable" side, not the "writable".
response._debugChannel === undefined
) {
if (
referencedChunk.status === PENDING &&
parentObject[0] === REACT_ELEMENT_TYPE &&
(key === '4' || key === '5')
) {
// If the parent object is an unparsed React element tuple, and this is a reference
// to the owner or debug stack. Then we expect the chunk to have been emitted earlier
// in the stream. It might be blocked on other things but chunk should no longer be pending.
// If it's still pending that suggests that it was referencing an object in the debug
// channel, but no debug channel was wired up so it's missing. In this case we can just
// drop the debug info instead of halting the whole stream.
return (null: any);
}
}

let handler: InitializationHandler;
if (initializingHandler) {
handler = initializingHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
*/

export function loadChunk(filename: string): Promise<mixed> {
return __turbopack_load__(filename);
return __turbopack_load_by_url__(filename);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
*/

export function loadChunk(filename: string): Promise<mixed> {
return __turbopack_load__(filename);
return __turbopack_load_by_url__(filename);
}
2 changes: 1 addition & 1 deletion scripts/flow/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ declare const __webpack_require__: ((id: string) => any) & {
u: string => string,
};

declare function __turbopack_load__(id: string): Promise<mixed>;
declare function __turbopack_load_by_url__(id: string): Promise<mixed>;
declare const __turbopack_require__: ((id: string) => any) & {
u: string => string,
};
Expand Down
2 changes: 1 addition & 1 deletion scripts/rollup/validate/eslintrc.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ module.exports = {
__webpack_require__: 'readonly',

// Flight Turbopack
__turbopack_load__: 'readonly',
__turbopack_load_by_url__: 'readonly',
__turbopack_require__: 'readonly',

// Flight Parcel
Expand Down
2 changes: 1 addition & 1 deletion scripts/rollup/validate/eslintrc.cjs2015.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = {
__webpack_require__: 'readonly',

// Flight Turbopack
__turbopack_load__: 'readonly',
__turbopack_load_by_url__: 'readonly',
__turbopack_require__: 'readonly',

// Flight Parcel
Expand Down
2 changes: 1 addition & 1 deletion scripts/rollup/validate/eslintrc.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ module.exports = {
__webpack_require__: 'readonly',

// Flight Turbopack
__turbopack_load__: 'readonly',
__turbopack_load_by_url__: 'readonly',
__turbopack_require__: 'readonly',

// Flight Parcel
Expand Down
Loading