Compare commits

..

2 Commits

Author SHA1 Message Date
Joe Savona
49bbeb91e5 [compiler] Add Intl formatter types and fix moduleTypeProvider fallback
Add type definitions for all Intl formatter objects (DateTimeFormat,
NumberFormat, Collator, PluralRules, ListFormat, RelativeTimeFormat,
Segmenter, DisplayNames) so the compiler understands that formatter
instances are immutable and their methods only read arguments.

Without these types, `new Intl.DateTimeFormat().format(date)` would
conservatively assume the format call captures `date` into the
formatter, creating an unnecessary dependency.

Also fix `#resolveModuleType` to always fall back to
`defaultModuleTypeProvider` when a custom `moduleTypeProvider` returns
null, so that tools like the snap runner that set their own provider
still get the default module types (react-hook-form, tanstack, etc.).
2026-02-25 13:30:58 -08:00
Ricky
074d96b9dd [flags] land enableTrustedTypesIntegration (#35816)
## Summary

This flag enables React's integration with the browser [Trusted Types
API](https://developer.mozilla.org/en-US/docs/Web/API/Trusted_Types_API).

The Trusted Types API is a browser security feature that helps prevent
DOM-based XSS attacks. When a site enables Trusted Types enforcement via
`Content-Security-Policy: require-trusted-types-for 'script'`, the
browser requires that values passed to DOM injection sinks (like
`innerHTML`) are typed objects (`TrustedHTML`, `TrustedScript`,
`TrustedScriptURL`) created through developer-defined sanitization
policies, rather than raw strings.

 ### What changed

Previously, React always coerced values to strings (via `'' + value`)
before passing them to DOM APIs like `setAttribute` and `innerHTML`.
This broke Trusted Types because it converted typed objects into plain
strings, which the browser would then reject under Trusted Types
enforcement.

React now passes values directly to DOM APIs without string coercion,
preserving Trusted Types objects so the browser can validate them. This
applies to `dangerouslySetInnerHTML`, all HTML and SVG attributes, and
URL attributes (`href`, `action`, etc).

 ### Before (broken)

Using Trusted Types with something like`dangerouslySetInnerHTML` would
throw:

 ```js
 const sanitizer = trustedTypes.createPolicy('sanitizer', {
   createHTML: (input) => DOMPurify.sanitize(input),
 });

 function Comment({text}) {
   const clean = sanitizer.createHTML(text);
   // clean is a TrustedHTML object, but React would call '' + clean,
   // converting it back to a plain string before setting innerHTML.
   // Under Trusted Types enforcement, the browser rejects the string:
   //
   //   TypeError: Failed to set 'innerHTML' on 'Element':
   //   This document requires 'TrustedHTML' assignment.
   return <div dangerouslySetInnerHTML={{__html: clean}} />;
 }
 ```

### After (works)

React now passes the TrustedHTML object directly to the DOM without
stringifying it:

```js
 const policy = trustedTypes.createPolicy('sanitizer', {
   createHTML: (input) => DOMPurify.sanitize(input),
 });

 function Comment({text}) {
   // TrustedHTML objects are passed directly to innerHTML
   return <div dangerouslySetInnerHTML={{__html: policy.createHTML(text)}} />;
 }

 function UserProfile({bio}) {
   // String attribute values also preserve Trusted Types objects
   return <div data-bio={policy.createHTML(bio)} />;
 }
 ```

 ## Non-breaking change

 - Sites using Trusted Types: React no longer breaks Trusted Types enforcement. TrustedHTML and TrustedScriptURL objects passed through React props are forwarded to the DOM without being stringified.
 - Sites not using Trusted Types: No behavior change. DOM APIs accept both strings and Trusted Types objects, so removing the explicit string coercion is functionally identical.
2026-02-25 14:49:30 -05:00
23 changed files with 542 additions and 383 deletions

View File

@@ -83,8 +83,6 @@ export class ProgramContext {
knownReferencedNames: Set<string> = new Set();
// generated imports
imports: Map<string, Map<string, NonLocalImportSpecifier>> = new Map();
// hoisted program-level constants
constants: Map<string, {uid: string; init: t.Expression}> = new Map();
constructor({
program,
@@ -184,16 +182,6 @@ export class ProgramContext {
this.knownReferencedNames.add(name);
}
addProgramConstant(name: string, init: () => t.Expression): string {
const existing = this.constants.get(name);
if (existing !== undefined) {
return existing.uid;
}
const uid = this.newUid(name);
this.constants.set(name, {uid, init: init()});
return uid;
}
assertGlobalBinding(
name: string,
localScope?: BabelScope,
@@ -314,13 +302,6 @@ export function addImportsToProgram(
}
}
}
for (const [, {uid, init}] of programContext.constants) {
stmts.push(
t.variableDeclaration('const', [
t.variableDeclarator(t.identifier(uid), init),
]),
);
}
path.unshiftContainer('body', stmts);
}

View File

@@ -502,16 +502,6 @@ export const EnvironmentConfigSchema = z.object({
* 3. Force update / external sync - should use useSyncExternalStore
*/
enableVerboseNoSetStateInEffect: z.boolean().default(false),
/**
* When enabled, the compiler emits `!Object.is(a, b)` instead of `a !== b`
* for dependency comparisons in memoized scopes. This matches the comparison
* semantics used by React's own hooks (useState, useMemo, etc.), which use
* Object.is. The main difference is in handling of NaN: `NaN !== NaN` is
* always true (causing memos to never be reused), while
* `Object.is(NaN, NaN)` is true (correctly treating NaN as unchanged).
*/
enableObjectIsComparison: z.boolean().default(false),
});
export type EnvironmentConfig = z.infer<typeof EnvironmentConfigSchema>;
@@ -802,18 +792,20 @@ export class Environment {
* NOTE: Zod doesn't work when specifying a function as a default, so we have to
* fallback to the default value here
*/
const moduleTypeProvider =
this.config.moduleTypeProvider ?? defaultModuleTypeProvider;
if (moduleTypeProvider == null) {
return null;
}
if (typeof moduleTypeProvider !== 'function') {
const moduleTypeProvider = this.config.moduleTypeProvider;
if (
moduleTypeProvider != null &&
typeof moduleTypeProvider !== 'function'
) {
CompilerError.throwInvalidConfig({
reason: `Expected a function for \`moduleTypeProvider\``,
loc,
});
}
const unparsedModuleConfig = moduleTypeProvider(moduleName);
const unparsedModuleConfig =
(typeof moduleTypeProvider === 'function'
? moduleTypeProvider(moduleName)
: null) ?? defaultModuleTypeProvider(moduleName);
if (unparsedModuleConfig != null) {
const parsedModuleConfig = TypeSchema.safeParse(unparsedModuleConfig);
if (!parsedModuleConfig.success) {

View File

@@ -28,6 +28,14 @@ import {
BuiltInWeakMapId,
BuiltInWeakSetId,
BuiltInEffectEventId,
BuiltInIntlDateTimeFormatId,
BuiltInIntlNumberFormatId,
BuiltInIntlCollatorId,
BuiltInIntlPluralRulesId,
BuiltInIntlListFormatId,
BuiltInIntlRelativeTimeFormatId,
BuiltInIntlSegmenterId,
BuiltInIntlDisplayNamesId,
ReanimatedSharedValueId,
ShapeRegistry,
addFunction,
@@ -620,6 +628,145 @@ const TYPED_GLOBALS: Array<[string, BuiltInType]> = [
true,
),
],
[
'Intl',
addObject(DEFAULT_SHAPES, 'Intl', [
[
'DateTimeFormat',
addFunction(
DEFAULT_SHAPES,
[],
{
positionalParams: [Effect.Read, Effect.Read],
restParam: null,
returnType: {
kind: 'Object',
shapeId: BuiltInIntlDateTimeFormatId,
},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Frozen,
},
null,
true,
),
],
[
'NumberFormat',
addFunction(
DEFAULT_SHAPES,
[],
{
positionalParams: [Effect.Read, Effect.Read],
restParam: null,
returnType: {kind: 'Object', shapeId: BuiltInIntlNumberFormatId},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Frozen,
},
null,
true,
),
],
[
'Collator',
addFunction(
DEFAULT_SHAPES,
[],
{
positionalParams: [Effect.Read, Effect.Read],
restParam: null,
returnType: {kind: 'Object', shapeId: BuiltInIntlCollatorId},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Frozen,
},
null,
true,
),
],
[
'PluralRules',
addFunction(
DEFAULT_SHAPES,
[],
{
positionalParams: [Effect.Read, Effect.Read],
restParam: null,
returnType: {kind: 'Object', shapeId: BuiltInIntlPluralRulesId},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Frozen,
},
null,
true,
),
],
[
'ListFormat',
addFunction(
DEFAULT_SHAPES,
[],
{
positionalParams: [Effect.Read, Effect.Read],
restParam: null,
returnType: {kind: 'Object', shapeId: BuiltInIntlListFormatId},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Frozen,
},
null,
true,
),
],
[
'RelativeTimeFormat',
addFunction(
DEFAULT_SHAPES,
[],
{
positionalParams: [Effect.Read, Effect.Read],
restParam: null,
returnType: {
kind: 'Object',
shapeId: BuiltInIntlRelativeTimeFormatId,
},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Frozen,
},
null,
true,
),
],
[
'Segmenter',
addFunction(
DEFAULT_SHAPES,
[],
{
positionalParams: [Effect.Read, Effect.Read],
restParam: null,
returnType: {kind: 'Object', shapeId: BuiltInIntlSegmenterId},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Frozen,
},
null,
true,
),
],
[
'DisplayNames',
addFunction(
DEFAULT_SHAPES,
[],
{
positionalParams: [Effect.Read, Effect.Read],
restParam: null,
returnType: {kind: 'Object', shapeId: BuiltInIntlDisplayNamesId},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Frozen,
},
null,
true,
),
],
]),
],
// TODO: rest of Global objects
];

View File

@@ -389,6 +389,16 @@ export const BuiltInEffectEventId = 'BuiltInEffectEventFunction';
// See getReanimatedModuleType() in Globals.ts — this is part of supporting Reanimated's ref-like types
export const ReanimatedSharedValueId = 'ReanimatedSharedValueId';
// Intl formatter instance shapes
export const BuiltInIntlDateTimeFormatId = 'BuiltInIntlDateTimeFormat';
export const BuiltInIntlNumberFormatId = 'BuiltInIntlNumberFormat';
export const BuiltInIntlCollatorId = 'BuiltInIntlCollator';
export const BuiltInIntlPluralRulesId = 'BuiltInIntlPluralRules';
export const BuiltInIntlListFormatId = 'BuiltInIntlListFormat';
export const BuiltInIntlRelativeTimeFormatId = 'BuiltInIntlRelativeTimeFormat';
export const BuiltInIntlSegmenterId = 'BuiltInIntlSegmenter';
export const BuiltInIntlDisplayNamesId = 'BuiltInIntlDisplayNames';
// ShapeRegistry with default definitions for built-ins.
export const BUILTIN_SHAPES: ShapeRegistry = new Map();
@@ -1232,6 +1242,297 @@ addObject(BUILTIN_SHAPES, BuiltInRefValueId, [
addObject(BUILTIN_SHAPES, ReanimatedSharedValueId, []);
/**
* Intl formatter instance shapes.
*
* All Intl formatter objects are immutable after construction — calling their
* methods does not modify the formatter. Methods like `format()` return
* primitives (strings/numbers), `formatToParts()` returns a new array, and
* `resolvedOptions()` returns a new object.
*/
/* Intl.DateTimeFormat instance */
addObject(BUILTIN_SHAPES, BuiltInIntlDateTimeFormatId, [
[
'format',
addFunction(BUILTIN_SHAPES, [], {
positionalParams: [Effect.Read],
restParam: null,
returnType: {kind: 'Primitive'},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Primitive,
}),
],
[
'formatToParts',
addFunction(BUILTIN_SHAPES, [], {
positionalParams: [Effect.Read],
restParam: null,
returnType: {kind: 'Object', shapeId: BuiltInArrayId},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Mutable,
}),
],
[
'formatRange',
addFunction(BUILTIN_SHAPES, [], {
positionalParams: [Effect.Read, Effect.Read],
restParam: null,
returnType: {kind: 'Primitive'},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Primitive,
}),
],
[
'formatRangeToParts',
addFunction(BUILTIN_SHAPES, [], {
positionalParams: [Effect.Read, Effect.Read],
restParam: null,
returnType: {kind: 'Object', shapeId: BuiltInArrayId},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Mutable,
}),
],
[
'resolvedOptions',
addFunction(BUILTIN_SHAPES, [], {
positionalParams: [],
restParam: null,
returnType: {kind: 'Object', shapeId: BuiltInObjectId},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Mutable,
}),
],
]);
/* Intl.NumberFormat instance */
addObject(BUILTIN_SHAPES, BuiltInIntlNumberFormatId, [
[
'format',
addFunction(BUILTIN_SHAPES, [], {
positionalParams: [Effect.Read],
restParam: null,
returnType: {kind: 'Primitive'},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Primitive,
}),
],
[
'formatToParts',
addFunction(BUILTIN_SHAPES, [], {
positionalParams: [Effect.Read],
restParam: null,
returnType: {kind: 'Object', shapeId: BuiltInArrayId},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Mutable,
}),
],
[
'formatRange',
addFunction(BUILTIN_SHAPES, [], {
positionalParams: [Effect.Read, Effect.Read],
restParam: null,
returnType: {kind: 'Primitive'},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Primitive,
}),
],
[
'formatRangeToParts',
addFunction(BUILTIN_SHAPES, [], {
positionalParams: [Effect.Read, Effect.Read],
restParam: null,
returnType: {kind: 'Object', shapeId: BuiltInArrayId},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Mutable,
}),
],
[
'resolvedOptions',
addFunction(BUILTIN_SHAPES, [], {
positionalParams: [],
restParam: null,
returnType: {kind: 'Object', shapeId: BuiltInObjectId},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Mutable,
}),
],
]);
/* Intl.Collator instance */
addObject(BUILTIN_SHAPES, BuiltInIntlCollatorId, [
[
'compare',
addFunction(BUILTIN_SHAPES, [], {
positionalParams: [Effect.Read, Effect.Read],
restParam: null,
returnType: {kind: 'Primitive'},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Primitive,
}),
],
[
'resolvedOptions',
addFunction(BUILTIN_SHAPES, [], {
positionalParams: [],
restParam: null,
returnType: {kind: 'Object', shapeId: BuiltInObjectId},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Mutable,
}),
],
]);
/* Intl.PluralRules instance */
addObject(BUILTIN_SHAPES, BuiltInIntlPluralRulesId, [
[
'select',
addFunction(BUILTIN_SHAPES, [], {
positionalParams: [Effect.Read],
restParam: null,
returnType: {kind: 'Primitive'},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Primitive,
}),
],
[
'selectRange',
addFunction(BUILTIN_SHAPES, [], {
positionalParams: [Effect.Read, Effect.Read],
restParam: null,
returnType: {kind: 'Primitive'},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Primitive,
}),
],
[
'resolvedOptions',
addFunction(BUILTIN_SHAPES, [], {
positionalParams: [],
restParam: null,
returnType: {kind: 'Object', shapeId: BuiltInObjectId},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Mutable,
}),
],
]);
/* Intl.ListFormat instance */
addObject(BUILTIN_SHAPES, BuiltInIntlListFormatId, [
[
'format',
addFunction(BUILTIN_SHAPES, [], {
positionalParams: [Effect.Read],
restParam: null,
returnType: {kind: 'Primitive'},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Primitive,
}),
],
[
'formatToParts',
addFunction(BUILTIN_SHAPES, [], {
positionalParams: [Effect.Read],
restParam: null,
returnType: {kind: 'Object', shapeId: BuiltInArrayId},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Mutable,
}),
],
[
'resolvedOptions',
addFunction(BUILTIN_SHAPES, [], {
positionalParams: [],
restParam: null,
returnType: {kind: 'Object', shapeId: BuiltInObjectId},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Mutable,
}),
],
]);
/* Intl.RelativeTimeFormat instance */
addObject(BUILTIN_SHAPES, BuiltInIntlRelativeTimeFormatId, [
[
'format',
addFunction(BUILTIN_SHAPES, [], {
positionalParams: [Effect.Read, Effect.Read],
restParam: null,
returnType: {kind: 'Primitive'},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Primitive,
}),
],
[
'formatToParts',
addFunction(BUILTIN_SHAPES, [], {
positionalParams: [Effect.Read, Effect.Read],
restParam: null,
returnType: {kind: 'Object', shapeId: BuiltInArrayId},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Mutable,
}),
],
[
'resolvedOptions',
addFunction(BUILTIN_SHAPES, [], {
positionalParams: [],
restParam: null,
returnType: {kind: 'Object', shapeId: BuiltInObjectId},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Mutable,
}),
],
]);
/* Intl.Segmenter instance */
addObject(BUILTIN_SHAPES, BuiltInIntlSegmenterId, [
[
'segment',
addFunction(BUILTIN_SHAPES, [], {
positionalParams: [Effect.Read],
restParam: null,
returnType: {kind: 'Poly'},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Mutable,
}),
],
[
'resolvedOptions',
addFunction(BUILTIN_SHAPES, [], {
positionalParams: [],
restParam: null,
returnType: {kind: 'Object', shapeId: BuiltInObjectId},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Mutable,
}),
],
]);
/* Intl.DisplayNames instance */
addObject(BUILTIN_SHAPES, BuiltInIntlDisplayNamesId, [
[
'of',
addFunction(BUILTIN_SHAPES, [], {
positionalParams: [Effect.Read],
restParam: null,
returnType: {kind: 'Primitive'},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Primitive,
}),
],
[
'resolvedOptions',
addFunction(BUILTIN_SHAPES, [], {
positionalParams: [],
restParam: null,
returnType: {kind: 'Object', shapeId: BuiltInObjectId},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Mutable,
}),
],
]);
addFunction(
BUILTIN_SHAPES,
[],

View File

@@ -182,8 +182,8 @@ export function codegenFunction(
const index = cx.synthesizeName('$i');
preface.push(
t.ifStatement(
codegenNegatedComparison(
cx,
t.binaryExpression(
'!==',
t.memberExpression(
t.identifier(cx.synthesizeName('$')),
t.numericLiteral(fastRefreshState.cacheIndex),
@@ -557,23 +557,6 @@ function codegenBlockNoReset(
return t.blockStatement(statements);
}
function codegenNegatedComparison(
cx: Context,
left: t.Expression,
right: t.Expression,
): t.Expression {
if (cx.env.config.enableObjectIsComparison) {
const isName = cx.env.programContext.addProgramConstant('is', () =>
t.memberExpression(t.identifier('Object'), t.identifier('is')),
);
return t.unaryExpression(
'!',
t.callExpression(t.identifier(isName), [left, right]),
);
}
return t.binaryExpression('!==', left, right);
}
function codegenReactiveScope(
cx: Context,
statements: Array<t.Statement>,
@@ -591,8 +574,8 @@ function codegenReactiveScope(
for (const dep of [...scope.dependencies].sort(compareScopeDependency)) {
const index = cx.nextCacheIndex;
const comparison = codegenNegatedComparison(
cx,
const comparison = t.binaryExpression(
'!==',
t.memberExpression(
t.identifier(cx.synthesizeName('$')),
t.numericLiteral(index),
@@ -737,8 +720,8 @@ function codegenReactiveScope(
const name: ValidIdentifierName = earlyReturnValue.value.name.value;
statements.push(
t.ifStatement(
codegenNegatedComparison(
cx,
t.binaryExpression(
'!==',
t.identifier(name),
t.callExpression(
t.memberExpression(t.identifier('Symbol'), t.identifier('for')),

View File

@@ -1,56 +0,0 @@
## Input
```javascript
// @enableObjectIsComparison
const is = null;
function Component(props) {
const x = [props.x];
console.log(is);
return x;
}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{x: 42}],
sequentialRenders: [{x: 42}, {x: 42}, {x: 3.14}],
};
```
## Code
```javascript
import { c as _c } from "react/compiler-runtime";
const _is = Object.is; // @enableObjectIsComparison
const is = null;
function Component(props) {
const $ = _c(2);
let t0;
if (!_is($[0], props.x)) {
t0 = [props.x];
$[0] = props.x;
$[1] = t0;
} else {
t0 = $[1];
}
const x = t0;
console.log(is);
return x;
}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ x: 42 }],
sequentialRenders: [{ x: 42 }, { x: 42 }, { x: 3.14 }],
};
```
### Eval output
(kind: ok) [42]
[42]
[3.14]
logs: [null,null,null]

View File

@@ -1,14 +0,0 @@
// @enableObjectIsComparison
const is = null;
function Component(props) {
const x = [props.x];
console.log(is);
return x;
}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{x: 42}],
sequentialRenders: [{x: 42}, {x: 42}, {x: 3.14}],
};

View File

@@ -1,91 +0,0 @@
## Input
```javascript
// @enableObjectIsComparison
import {makeArray} from 'shared-runtime';
function Component(props) {
let x = [];
if (props.cond) {
x.push(props.a);
return x;
} else {
return makeArray(props.b);
}
}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [],
sequentialRenders: [
{cond: true, a: 42},
{cond: true, a: 42},
{cond: false, b: 3.14},
{cond: false, b: 3.14},
],
};
```
## Code
```javascript
import { c as _c } from "react/compiler-runtime";
const is = Object.is; // @enableObjectIsComparison
import { makeArray } from "shared-runtime";
function Component(props) {
const $ = _c(6);
let t0;
if (!is($[0], props.a) || !is($[1], props.b) || !is($[2], props.cond)) {
t0 = Symbol.for("react.early_return_sentinel");
bb0: {
const x = [];
if (props.cond) {
x.push(props.a);
t0 = x;
break bb0;
} else {
let t1;
if (!is($[4], props.b)) {
t1 = makeArray(props.b);
$[4] = props.b;
$[5] = t1;
} else {
t1 = $[5];
}
t0 = t1;
break bb0;
}
}
$[0] = props.a;
$[1] = props.b;
$[2] = props.cond;
$[3] = t0;
} else {
t0 = $[3];
}
if (!is(t0, Symbol.for("react.early_return_sentinel"))) {
return t0;
}
}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [],
sequentialRenders: [
{ cond: true, a: 42 },
{ cond: true, a: 42 },
{ cond: false, b: 3.14 },
{ cond: false, b: 3.14 },
],
};
```
### Eval output
(kind: ok) [42]
[42]
[3.14]
[3.14]

View File

@@ -1,23 +0,0 @@
// @enableObjectIsComparison
import {makeArray} from 'shared-runtime';
function Component(props) {
let x = [];
if (props.cond) {
x.push(props.a);
return x;
} else {
return makeArray(props.b);
}
}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [],
sequentialRenders: [
{cond: true, a: 42},
{cond: true, a: 42},
{cond: false, b: 3.14},
{cond: false, b: 3.14},
],
};

View File

@@ -1,60 +0,0 @@
## Input
```javascript
// @enableObjectIsComparison @enableResetCacheOnSourceFileChanges
function Component(props) {
const x = [props.x];
return x;
}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{x: 42}],
sequentialRenders: [{x: 42}, {x: 42}, {x: 3.14}],
};
```
## Code
```javascript
import { c as _c } from "react/compiler-runtime";
const is = Object.is; // @enableObjectIsComparison @enableResetCacheOnSourceFileChanges
function Component(props) {
const $ = _c(3);
if (
!is(
$[0],
"eb2ec56d8fdd083c203a119ff37576dc8782330598640f725524102ae79e8b5c",
)
) {
for (let $i = 0; $i < 3; $i += 1) {
$[$i] = Symbol.for("react.memo_cache_sentinel");
}
$[0] = "eb2ec56d8fdd083c203a119ff37576dc8782330598640f725524102ae79e8b5c";
}
let t0;
if (!is($[1], props.x)) {
t0 = [props.x];
$[1] = props.x;
$[2] = t0;
} else {
t0 = $[2];
}
const x = t0;
return x;
}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ x: 42 }],
sequentialRenders: [{ x: 42 }, { x: 42 }, { x: 3.14 }],
};
```
### Eval output
(kind: ok) [42]
[42]
[3.14]

View File

@@ -1,11 +0,0 @@
// @enableObjectIsComparison @enableResetCacheOnSourceFileChanges
function Component(props) {
const x = [props.x];
return x;
}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{x: 42}],
sequentialRenders: [{x: 42}, {x: 42}, {x: 3.14}],
};

View File

@@ -1,49 +0,0 @@
## Input
```javascript
// @enableObjectIsComparison
function Component(props) {
const x = [props.x];
return x;
}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{x: 42}],
sequentialRenders: [{x: 42}, {x: 42}, {x: 3.14}],
};
```
## Code
```javascript
import { c as _c } from "react/compiler-runtime";
const is = Object.is; // @enableObjectIsComparison
function Component(props) {
const $ = _c(2);
let t0;
if (!is($[0], props.x)) {
t0 = [props.x];
$[0] = props.x;
$[1] = t0;
} else {
t0 = $[1];
}
const x = t0;
return x;
}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ x: 42 }],
sequentialRenders: [{ x: 42 }, { x: 42 }, { x: 3.14 }],
};
```
### Eval output
(kind: ok) [42]
[42]
[3.14]

View File

@@ -1,11 +0,0 @@
// @enableObjectIsComparison
function Component(props) {
const x = [props.x];
return x;
}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{x: 42}],
sequentialRenders: [{x: 42}, {x: 42}, {x: 3.14}],
};

View File

@@ -0,0 +1,62 @@
## Input
```javascript
function DateComponent({date}) {
const formatter = new Intl.DateTimeFormat('en-US');
return <time dateTime={date.toISOString()}>{formatter.format(date)}</time>;
}
export const FIXTURE_ENTRYPOINT = {
fn: DateComponent,
params: [{date: new Date('2024-01-01')}],
};
```
## Code
```javascript
import { c as _c } from "react/compiler-runtime";
function DateComponent(t0) {
const $ = _c(6);
const { date } = t0;
let t1;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t1 = new Intl.DateTimeFormat("en-US");
$[0] = t1;
} else {
t1 = $[0];
}
const formatter = t1;
let t2;
if ($[1] !== date) {
t2 = date.toISOString();
$[1] = date;
$[2] = t2;
} else {
t2 = $[2];
}
const t3 = formatter.format(date);
let t4;
if ($[3] !== t2 || $[4] !== t3) {
t4 = <time dateTime={t2}>{t3}</time>;
$[3] = t2;
$[4] = t3;
$[5] = t4;
} else {
t4 = $[5];
}
return t4;
}
export const FIXTURE_ENTRYPOINT = {
fn: DateComponent,
params: [{ date: new Date("2024-01-01") }],
};
```
### Eval output
(kind: ok) <time datetime="2024-01-01T00:00:00.000Z">12/31/2023</time>

View File

@@ -0,0 +1,10 @@
function DateComponent({date}) {
const formatter = new Intl.DateTimeFormat('en-US');
return <time dateTime={date.toISOString()}>{formatter.format(date)}</time>;
}
export const FIXTURE_ENTRYPOINT = {
fn: DateComponent,
params: [{date: new Date('2024-01-01')}],
};

View File

@@ -208,7 +208,7 @@ export const disableLegacyMode: boolean = true;
// in open source, but www codebase still relies on it. Need to remove.
export const disableCommentsAsDOMContainers: boolean = true;
export const enableTrustedTypesIntegration: boolean = false;
export const enableTrustedTypesIntegration: boolean = true;
// Prevent the value and checked attributes from syncing with their related
// DOM properties

View File

@@ -62,7 +62,7 @@ export const enableSuspenseAvoidThisFallback: boolean = false;
export const enableSuspenseCallback: boolean = true;
export const enableTaint: boolean = true;
export const enableTransitionTracing: boolean = false;
export const enableTrustedTypesIntegration: boolean = false;
export const enableTrustedTypesIntegration: boolean = true;
export const enableUpdaterTracking: boolean = __PROFILE__;
export const retryLaneExpirationMs = 5000;
export const syncLaneExpirationMs = 250;

View File

@@ -50,7 +50,7 @@ export const enableSuspenseAvoidThisFallback: boolean = false;
export const enableSuspenseCallback: boolean = false;
export const enableTaint: boolean = true;
export const enableTransitionTracing: boolean = false;
export const enableTrustedTypesIntegration: boolean = false;
export const enableTrustedTypesIntegration: boolean = true;
export const passChildrenWhenCloningPersistedNodes: boolean = false;
export const retryLaneExpirationMs = 5000;
export const syncLaneExpirationMs = 250;

View File

@@ -26,7 +26,7 @@ export const disableInputAttributeSyncing: boolean = false;
export const enableScopeAPI: boolean = false;
export const enableCreateEventHandleAPI: boolean = false;
export const enableSuspenseCallback: boolean = false;
export const enableTrustedTypesIntegration: boolean = false;
export const enableTrustedTypesIntegration: boolean = true;
export const disableTextareaChildren: boolean = false;
export const enableSuspenseAvoidThisFallback: boolean = false;
export const enableCPUSuspense: boolean = false;

View File

@@ -47,7 +47,7 @@ export const enableSuspenseAvoidThisFallback = false;
export const enableSuspenseCallback = false;
export const enableTaint = true;
export const enableTransitionTracing = false;
export const enableTrustedTypesIntegration = false;
export const enableTrustedTypesIntegration = true;
export const enableUpdaterTracking = false;
export const passChildrenWhenCloningPersistedNodes = false;
export const retryLaneExpirationMs = 5000;

View File

@@ -28,7 +28,7 @@ export const enableCreateEventHandleAPI: boolean = false;
export const enableSuspenseCallback: boolean = true;
export const disableLegacyContext: boolean = false;
export const disableLegacyContextForFunctionComponents: boolean = false;
export const enableTrustedTypesIntegration: boolean = false;
export const enableTrustedTypesIntegration: boolean = true;
export const disableTextareaChildren: boolean = false;
export const enableSuspenseAvoidThisFallback: boolean = true;
export const enableCPUSuspense: boolean = false;

View File

@@ -36,7 +36,6 @@ export const enableFragmentRefs: boolean = __VARIANT__;
export const enableFragmentRefsScrollIntoView: boolean = __VARIANT__;
export const enableFragmentRefsTextNodes: boolean = __VARIANT__;
export const enableInternalInstanceMap: boolean = __VARIANT__;
export const enableTrustedTypesIntegration: boolean = __VARIANT__;
export const enableParallelTransitions: boolean = __VARIANT__;
export const enableEffectEventMutationPhase: boolean = __VARIANT__;

View File

@@ -25,7 +25,6 @@ export const {
enableObjectFiber,
enableRetryLaneExpiration,
enableTransitionTracing,
enableTrustedTypesIntegration,
retryLaneExpirationMs,
syncLaneExpirationMs,
transitionLaneExpirationMs,
@@ -45,7 +44,7 @@ export const enableProfilerTimer = __PROFILE__;
export const enableProfilerCommitHooks = __PROFILE__;
export const enableProfilerNestedUpdatePhase = __PROFILE__;
export const enableUpdaterTracking = __PROFILE__;
export const enableTrustedTypesIntegration: boolean = true;
export const enableSuspenseAvoidThisFallback: boolean = true;
export const enableAsyncDebugInfo: boolean = true;