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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions packages/react-dom-bindings/src/client/DOMPropertyOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

import isAttributeNameSafe from '../shared/isAttributeNameSafe';
import {enableTrustedTypesIntegration} from 'shared/ReactFeatureFlags';
import {checkAttributeStringCoercion} from 'shared/CheckStringCoercion';
import {getFiberCurrentPropsFromNode} from './ReactDOMComponentTree';
import {trackHostMutation} from 'react-reconciler/src/ReactFiberMutationTracking';
Expand Down Expand Up @@ -124,10 +123,7 @@ export function setValueForAttribute(
if (__DEV__) {
checkAttributeStringCoercion(value, name);
}
node.setAttribute(
name,
enableTrustedTypesIntegration ? (value: any) : '' + (value: any),
);
node.setAttribute(name, (value: any));
}
}

Expand All @@ -152,10 +148,7 @@ export function setValueForKnownAttribute(
if (__DEV__) {
checkAttributeStringCoercion(value, name);
}
node.setAttribute(
name,
enableTrustedTypesIntegration ? (value: any) : '' + (value: any),
);
node.setAttribute(name, (value: any));
}

export function setValueForNamespacedAttribute(
Expand All @@ -180,11 +173,7 @@ export function setValueForNamespacedAttribute(
if (__DEV__) {
checkAttributeStringCoercion(value, name);
}
node.setAttributeNS(
namespace,
name,
enableTrustedTypesIntegration ? (value: any) : '' + (value: any),
);
node.setAttributeNS(namespace, name, (value: any));
}

export function setValueForPropertyOnCustomComponent(
Expand Down
18 changes: 4 additions & 14 deletions packages/react-dom-bindings/src/client/ReactDOMComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ import {
enableHydrationChangeEvent,
enableScrollEndPolyfill,
enableSrcObject,
enableTrustedTypesIntegration,
enableViewTransition,
} from 'shared/ReactFeatureFlags';
import {
Expand Down Expand Up @@ -525,9 +524,7 @@ function setProp(
if (__DEV__) {
checkAttributeStringCoercion(value, key);
}
const sanitizedValue = (sanitizeURL(
enableTrustedTypesIntegration ? value : '' + (value: any),
): any);
const sanitizedValue = (sanitizeURL(value): any);
domElement.setAttribute(key, sanitizedValue);
break;
}
Expand Down Expand Up @@ -596,9 +593,7 @@ function setProp(
if (__DEV__) {
checkAttributeStringCoercion(value, key);
}
const sanitizedValue = (sanitizeURL(
enableTrustedTypesIntegration ? value : '' + (value: any),
): any);
const sanitizedValue = (sanitizeURL(value): any);
domElement.setAttribute(key, sanitizedValue);
break;
}
Expand Down Expand Up @@ -699,9 +694,7 @@ function setProp(
if (__DEV__) {
checkAttributeStringCoercion(value, key);
}
const sanitizedValue = (sanitizeURL(
enableTrustedTypesIntegration ? value : '' + (value: any),
): any);
const sanitizedValue = (sanitizeURL(value): any);
domElement.setAttributeNS(xlinkNamespace, 'xlink:href', sanitizedValue);
break;
}
Expand All @@ -727,10 +720,7 @@ function setProp(
if (__DEV__) {
checkAttributeStringCoercion(value, key);
}
domElement.setAttribute(
key,
enableTrustedTypesIntegration ? (value: any) : '' + (value: any),
);
domElement.setAttribute(key, (value: any));
} else {
domElement.removeAttribute(key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ import {
import {
enableCreateEventHandleAPI,
enableScopeAPI,
enableTrustedTypesIntegration,
disableLegacyMode,
enableMoveBefore,
disableCommentsAsDOMContainers,
Expand Down Expand Up @@ -526,7 +525,7 @@ export function createInstance(
// set to true and it does not execute
const div = ownerDocument.createElement('div');
if (__DEV__) {
if (enableTrustedTypesIntegration && !didWarnScriptTags) {
if (!didWarnScriptTags) {
console.error(
'Encountered a script tag while rendering React component. ' +
'Scripts inside React components are never executed when rendering ' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import type {EventSystemFlags} from '../EventSystemFlags';
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
import type {FormStatus} from 'react-dom-bindings/src/shared/ReactDOMFormActions';

import {enableTrustedTypesIntegration} from 'shared/ReactFeatureFlags';
import {getFiberCurrentPropsFromNode} from '../../client/ReactDOMComponentTree';
import {startHostTransition} from 'react-reconciler/src/ReactFiberReconciler';
import {didCurrentEventScheduleTransition} from 'react-reconciler/src/ReactFiberRootScheduler';
Expand All @@ -39,9 +38,7 @@ function coerceFormActionProp(
if (__DEV__) {
checkAttributeStringCoercion(actionProp, 'action');
}
return (sanitizeURL(
enableTrustedTypesIntegration ? actionProp : '' + (actionProp: any),
): any);
return (sanitizeURL(actionProp): any);
}
}

Expand Down
24 changes: 8 additions & 16 deletions packages/react-dom/src/__tests__/ReactDOMFloat-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,14 +602,10 @@ describe('ReactDOMFloat', () => {
'> <script href="foo">\n' +
'\n' +
' in script (at **)',
...(gate('enableTrustedTypesIntegration')
? [
'Encountered a script tag while rendering React component. ' +
'Scripts inside React components are never executed when rendering on the client. ' +
'Consider using template tag instead (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template).\n' +
' in script (at **)',
]
: []),
'Encountered a script tag while rendering React component. ' +
'Scripts inside React components are never executed when rendering on the client. ' +
'Consider using template tag instead (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template).\n' +
' in script (at **)',
]);

root.render(
Expand Down Expand Up @@ -2753,14 +2749,10 @@ body {
'> <script itemProp="foo">\n' +
'\n' +
' in script (at **)',
...(gate('enableTrustedTypesIntegration')
? [
'Encountered a script tag while rendering React component. ' +
'Scripts inside React components are never executed when rendering on the client. ' +
'Consider using template tag instead (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template).\n' +
' in script (at **)',
]
: []),
'Encountered a script tag while rendering React component. ' +
'Scripts inside React components are never executed when rendering on the client. ' +
'Consider using template tag instead (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template).\n' +
' in script (at **)',
]);
});

Expand Down
6 changes: 1 addition & 5 deletions packages/react-dom/src/__tests__/ReactDOMForm-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2338,11 +2338,7 @@ describe('ReactDOMForm', () => {

await act(() => root.render(<Form action={instance} />));
await submit(formRef.current);
assertLog(
gate('enableTrustedTypesIntegration')
? [instance]
: ['stringified action'],
);
assertLog([instance]);
});

it('form actions should retain status when nested state changes', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ describe('ReactDOMServerIntegration - Untrusted URLs', () => {
expectedToStringCalls *= 2;
}

if (gate('enableTrustedTypesIntegration') && render === clientCleanRender) {
if (render === clientCleanRender) {
// Trusted types does another toString.
expectedToStringCalls += 1;
}
Expand Down
16 changes: 7 additions & 9 deletions packages/react-dom/src/__tests__/ReactEmptyComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,13 @@ describe('ReactEmptyComponent', () => {
}).not.toThrow();

expect(container.innerHTML).toBe('<script></script>');
if (gate('enableTrustedTypesIntegration')) {
assertConsoleErrorDev([
'Encountered a script tag while rendering React component. ' +
'Scripts inside React components are never executed when rendering on the client. ' +
'Consider using template tag instead (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template).\n' +
' in script (at **)\n' +
' in TogglingComponent (at **)',
]);
}
assertConsoleErrorDev([
'Encountered a script tag while rendering React component. ' +
'Scripts inside React components are never executed when rendering on the client. ' +
'Consider using template tag instead (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template).\n' +
' in script (at **)\n' +
' in TogglingComponent (at **)',
]);

const container2 = document.createElement('div');
const root2 = ReactDOMClient.createRoot(container2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,7 @@ describe('when Trusted Types are available in global object', () => {
expect(setAttributeCalls[0][0]).toBe(container.firstChild);
expect(setAttributeCalls[0][1]).toBe('data-foo');
// Ensure it didn't get stringified when passed to a DOM sink:
if (gate('enableTrustedTypesIntegration')) {
expect(setAttributeCalls[0][2]).toBe(ttObject1);
} else {
expect(setAttributeCalls[0][2]).toBe('<b>Hi</b>');
}
expect(setAttributeCalls[0][2]).toBe(ttObject1);

setAttributeCalls.length = 0;
await act(() => {
Expand All @@ -130,11 +126,7 @@ describe('when Trusted Types are available in global object', () => {
expect(setAttributeCalls[0][0]).toBe(container.firstChild);
expect(setAttributeCalls[0][1]).toBe('data-foo');
// Ensure it didn't get stringified when passed to a DOM sink:
if (gate('enableTrustedTypesIntegration')) {
expect(setAttributeCalls[0][2]).toBe(ttObject2);
} else {
expect(setAttributeCalls[0][2]).toBe('<b>Bye</b>');
}
expect(setAttributeCalls[0][2]).toBe(ttObject2);
} finally {
Element.prototype.setAttribute = setAttribute;
}
Expand All @@ -158,11 +150,7 @@ describe('when Trusted Types are available in global object', () => {
expect(setAttributeCalls[0][0]).toBe(container.firstChild);
expect(setAttributeCalls[0][1]).toBe('class');
// Ensure it didn't get stringified when passed to a DOM sink:
if (gate('enableTrustedTypesIntegration')) {
expect(setAttributeCalls[0][2]).toBe(ttObject1);
} else {
expect(setAttributeCalls[0][2]).toBe('<b>Hi</b>');
}
expect(setAttributeCalls[0][2]).toBe(ttObject1);

setAttributeCalls.length = 0;
await act(() => {
Expand All @@ -173,11 +161,7 @@ describe('when Trusted Types are available in global object', () => {
expect(setAttributeCalls[0][0]).toBe(container.firstChild);
expect(setAttributeCalls[0][1]).toBe('class');
// Ensure it didn't get stringified when passed to a DOM sink:
if (gate('enableTrustedTypesIntegration')) {
expect(setAttributeCalls[0][2]).toBe(ttObject2);
} else {
expect(setAttributeCalls[0][2]).toBe('<b>Bye</b>');
}
expect(setAttributeCalls[0][2]).toBe(ttObject2);
} finally {
Element.prototype.setAttribute = setAttribute;
}
Expand All @@ -202,11 +186,7 @@ describe('when Trusted Types are available in global object', () => {
expect(setAttributeNSCalls[0][1]).toBe('http://www.w3.org/1999/xlink');
expect(setAttributeNSCalls[0][2]).toBe('xlink:href');
// Ensure it didn't get stringified when passed to a DOM sink:
if (gate('enableTrustedTypesIntegration')) {
expect(setAttributeNSCalls[0][3]).toBe(ttObject1);
} else {
expect(setAttributeNSCalls[0][3]).toBe('<b>Hi</b>');
}
expect(setAttributeNSCalls[0][3]).toBe(ttObject1);

setAttributeNSCalls.length = 0;
await act(() => {
Expand All @@ -218,11 +198,7 @@ describe('when Trusted Types are available in global object', () => {
expect(setAttributeNSCalls[0][1]).toBe('http://www.w3.org/1999/xlink');
expect(setAttributeNSCalls[0][2]).toBe('xlink:href');
// Ensure it didn't get stringified when passed to a DOM sink:
if (gate('enableTrustedTypesIntegration')) {
expect(setAttributeNSCalls[0][3]).toBe(ttObject2);
} else {
expect(setAttributeNSCalls[0][3]).toBe('<b>Bye</b>');
}
expect(setAttributeNSCalls[0][3]).toBe(ttObject2);
} finally {
Element.prototype.setAttributeNS = setAttributeNS;
}
Expand All @@ -233,15 +209,13 @@ describe('when Trusted Types are available in global object', () => {
await act(() => {
root.render(<script>alert("I am not executed")</script>);
});
if (gate('enableTrustedTypesIntegration')) {
assertConsoleErrorDev([
'Encountered a script tag while rendering React component. ' +
'Scripts inside React components are never executed when rendering ' +
'on the client. Consider using template tag instead ' +
'(https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template).\n' +
' in script (at **)',
]);
}
assertConsoleErrorDev([
'Encountered a script tag while rendering React component. ' +
'Scripts inside React components are never executed when rendering ' +
'on the client. Consider using template tag instead ' +
'(https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template).\n' +
' in script (at **)',
]);

// check that the warning is printed only once
await act(() => {
Expand Down
2 changes: 0 additions & 2 deletions packages/shared/ReactFeatureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ 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 = true;

// Prevent the value and checked attributes from syncing with their related
// DOM properties
export const disableInputAttributeSyncing: boolean = false;
Expand Down
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.native-fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export const enableSuspenseAvoidThisFallback: boolean = false;
export const enableSuspenseCallback: boolean = true;
export const enableTaint: boolean = true;
export const enableTransitionTracing: boolean = false;
export const enableTrustedTypesIntegration: boolean = true;
export const enableUpdaterTracking: boolean = __PROFILE__;
export const retryLaneExpirationMs = 5000;
export const syncLaneExpirationMs = 250;
Expand Down
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.native-oss.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export const enableSuspenseAvoidThisFallback: boolean = false;
export const enableSuspenseCallback: boolean = false;
export const enableTaint: boolean = true;
export const enableTransitionTracing: boolean = false;
export const enableTrustedTypesIntegration: boolean = true;
export const passChildrenWhenCloningPersistedNodes: boolean = false;
export const retryLaneExpirationMs = 5000;
export const syncLaneExpirationMs = 250;
Expand Down
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.test-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export const disableInputAttributeSyncing: boolean = false;
export const enableScopeAPI: boolean = false;
export const enableCreateEventHandleAPI: boolean = false;
export const enableSuspenseCallback: boolean = false;
export const enableTrustedTypesIntegration: boolean = true;
export const disableTextareaChildren: boolean = false;
export const enableSuspenseAvoidThisFallback: boolean = false;
export const enableCPUSuspense: boolean = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export const enableSuspenseAvoidThisFallback = false;
export const enableSuspenseCallback = false;
export const enableTaint = true;
export const enableTransitionTracing = false;
export const enableTrustedTypesIntegration = true;
export const enableUpdaterTracking = false;
export const passChildrenWhenCloningPersistedNodes = false;
export const retryLaneExpirationMs = 5000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export const enableCreateEventHandleAPI: boolean = false;
export const enableSuspenseCallback: boolean = true;
export const disableLegacyContext: boolean = false;
export const disableLegacyContextForFunctionComponents: boolean = false;
export const enableTrustedTypesIntegration: boolean = true;
export const disableTextareaChildren: boolean = false;
export const enableSuspenseAvoidThisFallback: boolean = true;
export const enableCPUSuspense: boolean = false;
Expand Down
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ 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;
Expand Down
Loading