Skip to content

Commit b618bbb

Browse files
authored
[flags] land enableTrustedTypesIntegration (#37782)
it's on everywhere
1 parent 5efc6ed commit b618bbb

16 files changed

Lines changed: 42 additions & 120 deletions

‎packages/react-dom-bindings/src/client/DOMPropertyOperations.js‎

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*/
99

1010
import isAttributeNameSafe from '../shared/isAttributeNameSafe';
11-
import {enableTrustedTypesIntegration} from 'shared/ReactFeatureFlags';
1211
import {checkAttributeStringCoercion} from 'shared/CheckStringCoercion';
1312
import {getFiberCurrentPropsFromNode} from './ReactDOMComponentTree';
1413
import {trackHostMutation} from 'react-reconciler/src/ReactFiberMutationTracking';
@@ -132,10 +131,7 @@ export function setValueForAttribute(
132131
if (__DEV__) {
133132
checkAttributeStringCoercion(value, name);
134133
}
135-
node.setAttribute(
136-
name,
137-
enableTrustedTypesIntegration ? (value as any) : '' + (value as any),
138-
);
134+
node.setAttribute(name, value as any);
139135
}
140136
}
141137

@@ -160,10 +156,7 @@ export function setValueForKnownAttribute(
160156
if (__DEV__) {
161157
checkAttributeStringCoercion(value, name);
162158
}
163-
node.setAttribute(
164-
name,
165-
enableTrustedTypesIntegration ? (value as any) : '' + (value as any),
166-
);
159+
node.setAttribute(name, value as any);
167160
}
168161

169162
export function setValueForNamespacedAttribute(
@@ -188,11 +181,7 @@ export function setValueForNamespacedAttribute(
188181
if (__DEV__) {
189182
checkAttributeStringCoercion(value, name);
190183
}
191-
node.setAttributeNS(
192-
namespace,
193-
name,
194-
enableTrustedTypesIntegration ? (value as any) : '' + (value as any),
195-
);
184+
node.setAttributeNS(namespace, name, value as any);
196185
}
197186

198187
export function setValueForPropertyOnCustomComponent(

‎packages/react-dom-bindings/src/client/ReactDOMComponent.js‎

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ import {
7171
enableHydrationChangeEvent,
7272
enableScrollEndPolyfill,
7373
enableSrcObject,
74-
enableTrustedTypesIntegration,
7574
enableViewTransition,
7675
enableViewTransitionParentEnterExit,
7776
} from 'shared/ReactFeatureFlags';
@@ -533,14 +532,10 @@ function setProp(
533532
domElement.removeAttribute(key);
534533
break;
535534
}
536-
// `setAttribute` with objects becomes only `[object]` in IE8/9,
537-
// ('' + value) makes it output the correct toString()-value.
538535
if (__DEV__) {
539536
checkAttributeStringCoercion(value, key);
540537
}
541-
const sanitizedValue = sanitizeURL(
542-
enableTrustedTypesIntegration ? value : '' + (value as any),
543-
) as any;
538+
const sanitizedValue = sanitizeURL(value) as any;
544539
domElement.setAttribute(key, sanitizedValue);
545540
break;
546541
}
@@ -604,14 +599,10 @@ function setProp(
604599
domElement.removeAttribute(key);
605600
break;
606601
}
607-
// `setAttribute` with objects becomes only `[object]` in IE8/9,
608-
// ('' + value) makes it output the correct toString()-value.
609602
if (__DEV__) {
610603
checkAttributeStringCoercion(value, key);
611604
}
612-
const sanitizedValue = sanitizeURL(
613-
enableTrustedTypesIntegration ? value : '' + (value as any),
614-
) as any;
605+
const sanitizedValue = sanitizeURL(value) as any;
615606
domElement.setAttribute(key, sanitizedValue);
616607
break;
617608
}
@@ -711,14 +702,10 @@ function setProp(
711702
domElement.removeAttribute('xlink:href');
712703
break;
713704
}
714-
// `setAttribute` with objects becomes only `[object]` in IE8/9,
715-
// ('' + value) makes it output the correct toString()-value.
716705
if (__DEV__) {
717706
checkAttributeStringCoercion(value, key);
718707
}
719-
const sanitizedValue = sanitizeURL(
720-
enableTrustedTypesIntegration ? value : '' + (value as any),
721-
) as any;
708+
const sanitizedValue = sanitizeURL(value) as any;
722709
domElement.setAttributeNS(xlinkNamespace, 'xlink:href', sanitizedValue);
723710
break;
724711
}
@@ -744,10 +731,7 @@ function setProp(
744731
if (__DEV__) {
745732
checkAttributeStringCoercion(value, key);
746733
}
747-
domElement.setAttribute(
748-
key,
749-
enableTrustedTypesIntegration ? (value as any) : '' + (value as any),
750-
);
734+
domElement.setAttribute(key, value as any);
751735
} else {
752736
domElement.removeAttribute(key);
753737
}

‎packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ import {
124124
import {
125125
enableCreateEventHandleAPI,
126126
enableScopeAPI,
127-
enableTrustedTypesIntegration,
128127
disableLegacyMode,
129128
enableMoveBefore,
130129
disableCommentsAsDOMContainers,
@@ -574,7 +573,6 @@ export function createInstance(
574573
const div = ownerDocument.createElement('div');
575574
if (__DEV__) {
576575
if (
577-
enableTrustedTypesIntegration &&
578576
!didWarnScriptTags &&
579577
// Data block scripts are not executed by UAs anyway so
580578
// we don't need to warn: https://html.spec.whatwg.org/multipage/scripting.html#attr-script-type

‎packages/react-dom-bindings/src/events/plugins/FormActionEventPlugin.js‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import type {EventSystemFlags} from '../EventSystemFlags';
1414
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
1515
import type {FormStatus} from 'react-dom-bindings/src/shared/ReactDOMFormActions';
1616

17-
import {enableTrustedTypesIntegration} from 'shared/ReactFeatureFlags';
1817
import {getFiberCurrentPropsFromNode} from '../../client/ReactDOMComponentTree';
1918
import {startHostTransition} from 'react-reconciler/src/ReactFiberReconciler';
2019
import {didCurrentEventScheduleTransition} from 'react-reconciler/src/ReactFiberRootScheduler';
@@ -39,9 +38,7 @@ function coerceFormActionProp(
3938
if (__DEV__) {
4039
checkAttributeStringCoercion(actionProp, 'action');
4140
}
42-
return sanitizeURL(
43-
enableTrustedTypesIntegration ? actionProp : '' + (actionProp as any),
44-
) as any;
41+
return sanitizeURL(actionProp) as any;
4542
}
4643
}
4744

‎packages/react-dom/src/__tests__/ReactDOMFloat-test.js‎

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -602,14 +602,10 @@ describe('ReactDOMFloat', () => {
602602
'> <script href="foo">\n' +
603603
'\n' +
604604
' in script (at **)',
605-
...(gate('enableTrustedTypesIntegration')
606-
? [
607-
'Encountered a script tag while rendering React component. ' +
608-
'Scripts inside React components are never executed when rendering on the client. ' +
609-
'Consider using template tag instead (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template).\n' +
610-
' in script (at **)',
611-
]
612-
: []),
605+
'Encountered a script tag while rendering React component. ' +
606+
'Scripts inside React components are never executed when rendering on the client. ' +
607+
'Consider using template tag instead (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template).\n' +
608+
' in script (at **)',
613609
]);
614610

615611
root.render(
@@ -2753,14 +2749,10 @@ body {
27532749
'> <script itemProp="foo">\n' +
27542750
'\n' +
27552751
' in script (at **)',
2756-
...(gate('enableTrustedTypesIntegration')
2757-
? [
2758-
'Encountered a script tag while rendering React component. ' +
2759-
'Scripts inside React components are never executed when rendering on the client. ' +
2760-
'Consider using template tag instead (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template).\n' +
2761-
' in script (at **)',
2762-
]
2763-
: []),
2752+
'Encountered a script tag while rendering React component. ' +
2753+
'Scripts inside React components are never executed when rendering on the client. ' +
2754+
'Consider using template tag instead (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template).\n' +
2755+
' in script (at **)',
27642756
]);
27652757
});
27662758

‎packages/react-dom/src/__tests__/ReactDOMForm-test.js‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2328,7 +2328,8 @@ describe('ReactDOMForm', () => {
23282328
await submit(formRef.current);
23292329
assertLog([actionFn]);
23302330

2331-
// Everything else is toString-ed, unless trusted types are enabled.
2331+
// Everything else is passed through without being stringified, so that
2332+
// Trusted Types values reach the DOM as-is.
23322333
class MyAction {
23332334
toString() {
23342335
return 'stringified action';
@@ -2338,11 +2339,7 @@ describe('ReactDOMForm', () => {
23382339

23392340
await act(() => root.render(<Form action={instance} />));
23402341
await submit(formRef.current);
2341-
assertLog(
2342-
gate('enableTrustedTypesIntegration')
2343-
? [instance]
2344-
: ['stringified action'],
2345-
);
2342+
assertLog([instance]);
23462343
});
23472344

23482345
it('form actions should retain status when nested state changes', async () => {

‎packages/react-dom/src/__tests__/ReactDOMServerIntegrationUntrustedURL-test.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,9 @@ describe('ReactDOMServerIntegration - Untrusted URLs', () => {
212212
expectedToStringCalls *= 2;
213213
}
214214

215-
if (gate('enableTrustedTypesIntegration') && render === clientCleanRender) {
216-
// Trusted types does another toString.
215+
if (render === clientCleanRender) {
216+
// Passing the value to setAttribute without stringifying it first (to
217+
// support Trusted Types) does another toString.
217218
expectedToStringCalls += 1;
218219
}
219220

‎packages/react-dom/src/__tests__/ReactEmptyComponent-test.js‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,13 @@ describe('ReactEmptyComponent', () => {
178178
}).not.toThrow();
179179

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

191189
const container2 = document.createElement('div');
192190
const root2 = ReactDOMClient.createRoot(container2);

‎packages/react-dom/src/client/__tests__/trustedTypes-test.internal.js‎

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,7 @@ describe('when Trusted Types are available in global object', () => {
115115
expect(setAttributeCalls[0][0]).toBe(container.firstChild);
116116
expect(setAttributeCalls[0][1]).toBe('data-foo');
117117
// Ensure it didn't get stringified when passed to a DOM sink:
118-
if (gate('enableTrustedTypesIntegration')) {
119-
expect(setAttributeCalls[0][2]).toBe(ttObject1);
120-
} else {
121-
expect(setAttributeCalls[0][2]).toBe('<b>Hi</b>');
122-
}
118+
expect(setAttributeCalls[0][2]).toBe(ttObject1);
123119

124120
setAttributeCalls.length = 0;
125121
await act(() => {
@@ -130,11 +126,7 @@ describe('when Trusted Types are available in global object', () => {
130126
expect(setAttributeCalls[0][0]).toBe(container.firstChild);
131127
expect(setAttributeCalls[0][1]).toBe('data-foo');
132128
// Ensure it didn't get stringified when passed to a DOM sink:
133-
if (gate('enableTrustedTypesIntegration')) {
134-
expect(setAttributeCalls[0][2]).toBe(ttObject2);
135-
} else {
136-
expect(setAttributeCalls[0][2]).toBe('<b>Bye</b>');
137-
}
129+
expect(setAttributeCalls[0][2]).toBe(ttObject2);
138130
} finally {
139131
Element.prototype.setAttribute = setAttribute;
140132
}
@@ -158,11 +150,7 @@ describe('when Trusted Types are available in global object', () => {
158150
expect(setAttributeCalls[0][0]).toBe(container.firstChild);
159151
expect(setAttributeCalls[0][1]).toBe('class');
160152
// Ensure it didn't get stringified when passed to a DOM sink:
161-
if (gate('enableTrustedTypesIntegration')) {
162-
expect(setAttributeCalls[0][2]).toBe(ttObject1);
163-
} else {
164-
expect(setAttributeCalls[0][2]).toBe('<b>Hi</b>');
165-
}
153+
expect(setAttributeCalls[0][2]).toBe(ttObject1);
166154

167155
setAttributeCalls.length = 0;
168156
await act(() => {
@@ -173,11 +161,7 @@ describe('when Trusted Types are available in global object', () => {
173161
expect(setAttributeCalls[0][0]).toBe(container.firstChild);
174162
expect(setAttributeCalls[0][1]).toBe('class');
175163
// Ensure it didn't get stringified when passed to a DOM sink:
176-
if (gate('enableTrustedTypesIntegration')) {
177-
expect(setAttributeCalls[0][2]).toBe(ttObject2);
178-
} else {
179-
expect(setAttributeCalls[0][2]).toBe('<b>Bye</b>');
180-
}
164+
expect(setAttributeCalls[0][2]).toBe(ttObject2);
181165
} finally {
182166
Element.prototype.setAttribute = setAttribute;
183167
}
@@ -202,11 +186,7 @@ describe('when Trusted Types are available in global object', () => {
202186
expect(setAttributeNSCalls[0][1]).toBe('http://www.w3.org/1999/xlink');
203187
expect(setAttributeNSCalls[0][2]).toBe('xlink:href');
204188
// Ensure it didn't get stringified when passed to a DOM sink:
205-
if (gate('enableTrustedTypesIntegration')) {
206-
expect(setAttributeNSCalls[0][3]).toBe(ttObject1);
207-
} else {
208-
expect(setAttributeNSCalls[0][3]).toBe('<b>Hi</b>');
209-
}
189+
expect(setAttributeNSCalls[0][3]).toBe(ttObject1);
210190

211191
setAttributeNSCalls.length = 0;
212192
await act(() => {
@@ -218,11 +198,7 @@ describe('when Trusted Types are available in global object', () => {
218198
expect(setAttributeNSCalls[0][1]).toBe('http://www.w3.org/1999/xlink');
219199
expect(setAttributeNSCalls[0][2]).toBe('xlink:href');
220200
// Ensure it didn't get stringified when passed to a DOM sink:
221-
if (gate('enableTrustedTypesIntegration')) {
222-
expect(setAttributeNSCalls[0][3]).toBe(ttObject2);
223-
} else {
224-
expect(setAttributeNSCalls[0][3]).toBe('<b>Bye</b>');
225-
}
201+
expect(setAttributeNSCalls[0][3]).toBe(ttObject2);
226202
} finally {
227203
Element.prototype.setAttributeNS = setAttributeNS;
228204
}
@@ -233,15 +209,13 @@ describe('when Trusted Types are available in global object', () => {
233209
await act(() => {
234210
root.render(<script>alert("I am not executed")</script>);
235211
});
236-
if (gate('enableTrustedTypesIntegration')) {
237-
assertConsoleErrorDev([
238-
'Encountered a script tag while rendering React component. ' +
239-
'Scripts inside React components are never executed when rendering ' +
240-
'on the client. Consider using template tag instead ' +
241-
'(https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template).\n' +
242-
' in script (at **)',
243-
]);
244-
}
212+
assertConsoleErrorDev([
213+
'Encountered a script tag while rendering React component. ' +
214+
'Scripts inside React components are never executed when rendering ' +
215+
'on the client. Consider using template tag instead ' +
216+
'(https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template).\n' +
217+
' in script (at **)',
218+
]);
245219

246220
// check that the warning is printed only once
247221
await act(() => {

‎packages/shared/ReactFeatureFlags.js‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,6 @@ export const disableLegacyMode: boolean = true;
218218
// in open source, but www codebase still relies on it. Need to remove.
219219
export const disableCommentsAsDOMContainers: boolean = true;
220220

221-
export const enableTrustedTypesIntegration: boolean = true;
222-
223221
// Prevent the value and checked attributes from syncing with their related
224222
// DOM properties
225223
export const disableInputAttributeSyncing: boolean = false;

0 commit comments

Comments
 (0)