Skip to content
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 @@ -2327,7 +2327,7 @@ function codegenJsxAttribute(
}
}

const JSX_TEXT_CHILD_REQUIRES_EXPR_CONTAINER_PATTERN = /[<>&]/;
const JSX_TEXT_CHILD_REQUIRES_EXPR_CONTAINER_PATTERN = /[<>&{}]/;
function codegenJsxElement(
cx: Context,
place: Place,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

## Input

```javascript
function Test() {
return (
<div>
If the string contains the string &#123;pageNumber&#125; it will be
replaced by the page number.
</div>
);
}

export const FIXTURE_ENTRYPOINT = {
fn: Test,
params: [],
};

```

## Code

```javascript
import { c as _c } from "react/compiler-runtime";
function Test() {
const $ = _c(1);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = (
<div>
{
"If the string contains the string {pageNumber} it will be replaced by the page number."
}
</div>
);
$[0] = t0;
} else {
t0 = $[0];
}
return t0;
}

export const FIXTURE_ENTRYPOINT = {
fn: Test,
params: [],
};

```

### Eval output
(kind: ok) <div>If the string contains the string {pageNumber} it will be replaced by the page number.</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function Test() {
return (
<div>
If the string contains the string &#123;pageNumber&#125; it will be
replaced by the page number.
</div>
);
}

export const FIXTURE_ENTRYPOINT = {
fn: Test,
params: [],
};
2 changes: 1 addition & 1 deletion compiler/packages/eslint-plugin-react-compiler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import react from "eslint-plugin-react"
export default [
// Your existing config
{ ...pluginReact.configs.flat.recommended, settings: { react: { version: "detect" } } },
+ reactCompiler.config.recommended
+ reactCompiler.configs.recommended
]
```

Expand Down
17 changes: 6 additions & 11 deletions packages/react-client/src/ReactFlightClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
ReactTimeInfo,
ReactStackTrace,
ReactCallSite,
ReactErrorInfoDev,
} from 'shared/ReactTypes';
import type {LazyComponent} from 'react/src/ReactLazy';

Expand Down Expand Up @@ -2123,18 +2124,12 @@ function resolveErrorProd(response: Response): Error {

function resolveErrorDev(
response: Response,
errorInfo: {
name: string,
message: string,
stack: ReactStackTrace,
env: string,
...
},
errorInfo: ReactErrorInfoDev,
): Error {
const name: string = errorInfo.name;
const message: string = errorInfo.message;
const stack: ReactStackTrace = errorInfo.stack;
const env: string = errorInfo.env;
const name = errorInfo.name;
const message = errorInfo.message;
const stack = errorInfo.stack;
const env = errorInfo.env;

if (!__DEV__) {
// These errors should never make it into a build so we don't need to encode them in codes.json
Expand Down
1 change: 1 addition & 0 deletions packages/react-client/src/__tests__/ReactFlight-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,7 @@ describe('ReactFlight', () => {
errors: [
{
message: 'This is an error',
name: 'Error',
stack: expect.stringContaining(
'Error: This is an error\n' +
' at eval (eval at testFunction (inspected-page.html:29:11),%20%3Canonymous%3E:1:35)\n' +
Expand Down
24 changes: 23 additions & 1 deletion packages/react-debug-tools/src/ReactDebugHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ function getPrimitiveStackCache(): Map<string, Array<any>> {
}

Dispatcher.useId();

if (typeof Dispatcher.useResourceEffect === 'function') {
Dispatcher.useResourceEffect(() => ({}), []);
}
if (typeof Dispatcher.useEffectEvent === 'function') {
Dispatcher.useEffectEvent((args: empty) => {});
}
} finally {
readHookLog = hookLog;
hookLog = [];
Expand Down Expand Up @@ -749,6 +756,20 @@ function useResourceEffect(
});
}

function useEffectEvent<Args, F: (...Array<Args>) => mixed>(callback: F): F {
nextHook();
hookLog.push({
displayName: null,
primitive: 'EffectEvent',
stackError: new Error(),
value: callback,
debugInfo: null,
dispatcherHookName: 'EffectEvent',
});

return callback;
}

const Dispatcher: DispatcherType = {
use,
readContext,
Expand All @@ -773,6 +794,7 @@ const Dispatcher: DispatcherType = {
useFormState,
useActionState,
useHostTransitionStatus,
useEffectEvent,
useResourceEffect,
};

Expand Down Expand Up @@ -962,7 +984,7 @@ function parseHookName(functionName: void | string): string {
startIndex += 'unstable_'.length;
}

if (functionName.slice(startIndex).startsWith('unstable_')) {
if (functionName.slice(startIndex).startsWith('experimental_')) {
startIndex += 'experimental_'.length;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import NestedProps from './NestedProps';
import SimpleValues from './SimpleValues';
import SymbolKeys from './SymbolKeys';
import UseMemoCache from './UseMemoCache';
import UseEffectEvent from './UseEffectEvent';

// TODO Add Immutable JS example

Expand All @@ -36,6 +37,7 @@ export default function InspectableElements(): React.Node {
<CircularReferences />
<SymbolKeys />
<UseMemoCache />
<UseEffectEvent />
</Fragment>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as React from 'react';

const {experimental_useEffectEvent, useState, useEffect} = React;

export default function UseEffectEvent(): React.Node {
return (
<>
<SingleHookCase />
<HookTreeCase />
</>
);
}

function SingleHookCase() {
const onClick = experimental_useEffectEvent(() => {});

return <div onClick={onClick} />;
}

function useCustomHook() {
const [state, setState] = useState();
const onClick = experimental_useEffectEvent(() => {});
useEffect(() => {});

return [state, setState, onClick];
}

function HookTreeCase() {
const onClick = useCustomHook();

return <div onClick={onClick} />;
}
16 changes: 10 additions & 6 deletions packages/react-server/src/ReactFlightServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ import type {
ReactTimeInfo,
ReactStackTrace,
ReactCallSite,
ReactErrorInfo,
ReactErrorInfoDev,
} from 'shared/ReactTypes';
import type {ReactElement} from 'shared/ReactElementType';
import type {LazyComponent} from 'react/src/ReactLazy';
Expand Down Expand Up @@ -3093,8 +3095,8 @@ function emitPostponeChunk(

function serializeErrorValue(request: Request, error: Error): string {
if (__DEV__) {
let name;
let message;
let name: string = 'Error';
let message: string;
let stack: ReactStackTrace;
let env = (0, request.environmentName)();
try {
Expand All @@ -3112,7 +3114,7 @@ function serializeErrorValue(request: Request, error: Error): string {
message = 'An error occurred but serializing the error message failed.';
stack = [];
}
const errorInfo = {name, message, stack, env};
const errorInfo: ReactErrorInfoDev = {name, message, stack, env};
const id = outlineModel(request, errorInfo);
return '$Z' + id.toString(16);
} else {
Expand All @@ -3129,13 +3131,15 @@ function emitErrorChunk(
digest: string,
error: mixed,
): void {
let errorInfo: any;
let errorInfo: ReactErrorInfo;
if (__DEV__) {
let message;
let name: string = 'Error';
let message: string;
let stack: ReactStackTrace;
let env = (0, request.environmentName)();
try {
if (error instanceof Error) {
name = error.name;
// eslint-disable-next-line react-internal/safe-string-coercion
message = String(error.message);
stack = filterStackTrace(request, error, 0);
Expand All @@ -3157,7 +3161,7 @@ function emitErrorChunk(
message = 'An error occurred but serializing the error message failed.';
stack = [];
}
errorInfo = {digest, message, stack, env};
errorInfo = {digest, name, message, stack, env};
} else {
errorInfo = {digest};
}
Expand Down
14 changes: 14 additions & 0 deletions packages/shared/ReactTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,20 @@ export type ReactEnvironmentInfo = {
+env: string,
};

export type ReactErrorInfoProd = {
+digest: string,
};

export type ReactErrorInfoDev = {
+digest?: string,
+name: string,
+message: string,
+stack: ReactStackTrace,
+env: string,
};

export type ReactErrorInfo = ReactErrorInfoProd | ReactErrorInfoDev;

export type ReactAsyncInfo = {
+type: string,
// Stashed Data for the Specific Execution Environment. Not part of the transport protocol
Expand Down
Loading