Skip to content

Commit 4027f2a

Browse files
authored
Break up require/import statements in strings (#18222)
1 parent 024a764 commit 4027f2a

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

packages/react-reconciler/src/ReactFiberWorkLoop.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2937,11 +2937,15 @@ export function warnIfNotScopedWithMatchingAct(fiber: Fiber): void {
29372937
"It looks like you're using the wrong act() around your test interactions.\n" +
29382938
'Be sure to use the matching version of act() corresponding to your renderer:\n\n' +
29392939
'// for react-dom:\n' +
2940-
"import {act} from 'react-dom/test-utils';\n" +
2940+
// Break up imports to avoid accidentally parsing them as dependencies.
2941+
'import {act} fr' +
2942+
"om 'react-dom/test-utils';\n" +
29412943
'// ...\n' +
29422944
'act(() => ...);\n\n' +
29432945
'// for react-test-renderer:\n' +
2944-
"import TestRenderer from 'react-test-renderer';\n" +
2946+
// Break up imports to avoid accidentally parsing them as dependencies.
2947+
'import TestRenderer fr' +
2948+
"om react-test-renderer';\n" +
29452949
'const {act} = TestRenderer;\n' +
29462950
'// ...\n' +
29472951
'act(() => ...);' +
@@ -3027,7 +3031,9 @@ export function warnIfUnmockedScheduler(fiber: Fiber) {
30273031
'In Concurrent or Sync modes, the "scheduler" module needs to be mocked ' +
30283032
'to guarantee consistent behaviour across tests and browsers. ' +
30293033
'For example, with jest: \n' +
3030-
"jest.mock('scheduler', () => require('scheduler/unstable_mock'));\n\n" +
3034+
// Break up requires to avoid accidentally parsing them as dependencies.
3035+
"jest.mock('scheduler', () => require" +
3036+
"('scheduler/unstable_mock'));\n\n" +
30313037
'For more info, visit https://fb.me/react-mock-scheduler',
30323038
);
30333039
} else if (warnAboutUnmockedScheduler === true) {
@@ -3036,7 +3042,9 @@ export function warnIfUnmockedScheduler(fiber: Fiber) {
30363042
'Starting from React v17, the "scheduler" module will need to be mocked ' +
30373043
'to guarantee consistent behaviour across tests and browsers. ' +
30383044
'For example, with jest: \n' +
3039-
"jest.mock('scheduler', () => require('scheduler/unstable_mock'));\n\n" +
3045+
// Break up requires to avoid accidentally parsing them as dependencies.
3046+
"jest.mock('scheduler', () => require" +
3047+
"('scheduler/unstable_mock'));\n\n" +
30403048
'For more info, visit https://fb.me/react-mock-scheduler',
30413049
);
30423050
}

packages/shared/ReactLazyComponent.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ export function initializeLazyComponentType(
5050
console.error(
5151
'lazy: Expected the result of a dynamic import() call. ' +
5252
'Instead received: %s\n\nYour code should look like: \n ' +
53-
"const MyComponent = lazy(() => import('./MyComponent'))",
53+
// Break up imports to avoid accidentally parsing them as dependencies.
54+
'const MyComponent = lazy(() => imp' +
55+
"ort('./MyComponent'))",
5456
moduleObject,
5557
);
5658
}

0 commit comments

Comments
 (0)