Skip to content

Commit 2c0c217

Browse files
committed
Add more gates
1 parent caca078 commit 2c0c217

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,14 @@ describe('ReactDOMFloat', () => {
608608
'> <script href="foo">\n' +
609609
'\n' +
610610
' in script (at **)',
611+
...(gate('enableTrustedTypesIntegration')
612+
? [
613+
'Encountered a script tag while rendering React component. ' +
614+
'Scripts inside React components are never executed when rendering on the client. ' +
615+
'Consider using template tag instead (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template).\n' +
616+
' in script (at **)',
617+
]
618+
: []),
611619
]);
612620

613621
root.render(
@@ -2754,6 +2762,14 @@ body {
27542762
'> <script itemProp="foo">\n' +
27552763
'\n' +
27562764
' in script (at **)',
2765+
...(gate('enableTrustedTypesIntegration')
2766+
? [
2767+
'Encountered a script tag while rendering React component. ' +
2768+
'Scripts inside React components are never executed when rendering on the client. ' +
2769+
'Consider using template tag instead (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template).\n' +
2770+
' in script (at **)',
2771+
]
2772+
: []),
27572773
]);
27582774
});
27592775

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2285,15 +2285,21 @@ describe('ReactDOMForm', () => {
22852285
await submit(formRef.current);
22862286
assertLog([actionFn]);
22872287

2288-
// Everything else is toString-ed
2288+
// Everything else is toString-ed, unless trusted types are enabled.
22892289
class MyAction {
22902290
toString() {
22912291
return 'stringified action';
22922292
}
22932293
}
2294-
await act(() => root.render(<Form action={new MyAction()} />));
2294+
const instance = new MyAction();
2295+
2296+
await act(() => root.render(<Form action={instance} />));
22952297
await submit(formRef.current);
2296-
assertLog(['stringified action']);
2298+
assertLog(
2299+
gate('enableTrustedTypesIntegration')
2300+
? [instance]
2301+
: ['stringified action'],
2302+
);
22972303
});
22982304

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

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

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

215+
if (gate('enableTrustedTypesIntegration') && render === clientCleanRender) {
216+
// Trusted types does another toString.
217+
expectedToStringCalls += 1;
218+
}
219+
215220
let toStringCalls = 0;
216221
const firstIsSafe = {
217222
toString() {

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ let TogglingComponent;
1717
let act;
1818
let Scheduler;
1919
let assertLog;
20+
let assertConsoleErrorDev;
2021

2122
let container;
2223

@@ -34,6 +35,7 @@ describe('ReactEmptyComponent', () => {
3435
const InternalTestUtils = require('internal-test-utils');
3536
act = InternalTestUtils.act;
3637
assertLog = InternalTestUtils.assertLog;
38+
assertConsoleErrorDev = InternalTestUtils.assertConsoleErrorDev;
3739

3840
container = document.createElement('div');
3941

@@ -175,6 +177,17 @@ describe('ReactEmptyComponent', () => {
175177
});
176178
}).not.toThrow();
177179

180+
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+
}
190+
178191
const container2 = document.createElement('div');
179192
const root2 = ReactDOMClient.createRoot(container2);
180193
expect(() => {
@@ -189,6 +202,7 @@ describe('ReactEmptyComponent', () => {
189202
'mount SCRIPT',
190203
'update undefined',
191204
]);
205+
expect(container2.innerHTML).toBe('');
192206
});
193207

194208
it(

0 commit comments

Comments
 (0)