GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Don't trigger lazy in DEV during element creation (#19871) · react/react@bc6b7b6

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages
    • react-reconciler/src/__tests__
      • ReactLazy-test.internal.js
    • react/src
      • ReactElementValidator.js
      • __tests__
        • ReactElementJSX-test.js
        • ReactElementValidator-test.internal.js
        • ReactJSXElementValidator-test.js
      • jsx
        • ReactJSXElementValidator.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/react-reconciler/src/__tests__/ReactLazy-test.internal.js‎

Copy file name to clipboardExpand all lines: packages/react-reconciler/src/__tests__/ReactLazy-test.internal.js
+1-7Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -979,13 +979,7 @@ describe('ReactLazy', () => {
979979
},
980980
);
981981

982-
if (__DEV__) {
983-
// Getting the name for the warning cause the loading to start early.
984-
expect(Scheduler).toHaveYielded(['Started loading']);
985-
expect(Scheduler).toFlushAndYield(['Loading...']);
986-
} else {
987-
expect(Scheduler).toFlushAndYield(['Started loading', 'Loading...']);
988-
}
982+
expect(Scheduler).toFlushAndYield(['Started loading', 'Loading...']);
989983
expect(root).not.toMatchRenderedOutput(<div>AB</div>);
990984

991985
await Promise.resolve();
Collapse file

‎packages/react/src/ReactElementValidator.js‎

Copy file name to clipboardExpand all lines: packages/react/src/ReactElementValidator.js
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ function validatePropTypes(element) {
211211
if (type === null || type === undefined || typeof type === 'string') {
212212
return;
213213
}
214-
const name = getComponentName(type);
215214
let propTypes;
216215
if (typeof type === 'function') {
217216
propTypes = type.propTypes;
@@ -227,9 +226,13 @@ function validatePropTypes(element) {
227226
return;
228227
}
229228
if (propTypes) {
229+
// Intentionally inside to avoid triggering lazy initializers:
230+
const name = getComponentName(type);
230231
checkPropTypes(propTypes, element.props, 'prop', name, element);
231232
} else if (type.PropTypes !== undefined && !propTypesMisspellWarningShown) {
232233
propTypesMisspellWarningShown = true;
234+
// Intentionally inside to avoid triggering lazy initializers:
235+
const name = getComponentName(type);
233236
console.error(
234237
'Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?',
235238
name || 'Unknown',
Collapse file

‎packages/react/src/__tests__/ReactElementJSX-test.js‎

Copy file name to clipboardExpand all lines: packages/react/src/__tests__/ReactElementJSX-test.js
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,4 +415,18 @@ describe('ReactElement.jsx', () => {
415415
// TODO: an explicit expect for no warning?
416416
ReactDOM.render(JSXRuntime.jsx(Parent, {}), container);
417417
});
418+
419+
it('does not call lazy initializers eagerly', () => {
420+
let didCall = false;
421+
const Lazy = React.lazy(() => {
422+
didCall = true;
423+
return {then() {}};
424+
});
425+
if (__DEV__) {
426+
JSXDEVRuntime.jsxDEV(Lazy, {});
427+
} else {
428+
JSXRuntime.jsx(Lazy, {});
429+
}
430+
expect(didCall).toBe(false);
431+
});
418432
});
Collapse file

‎packages/react/src/__tests__/ReactElementValidator-test.internal.js‎

Copy file name to clipboardExpand all lines: packages/react/src/__tests__/ReactElementValidator-test.internal.js
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,4 +532,14 @@ describe('ReactElementValidator', () => {
532532
{withoutStack: true},
533533
);
534534
});
535+
536+
it('does not call lazy initializers eagerly', () => {
537+
let didCall = false;
538+
const Lazy = React.lazy(() => {
539+
didCall = true;
540+
return {then() {}};
541+
});
542+
React.createElement(Lazy);
543+
expect(didCall).toBe(false);
544+
});
535545
});
Collapse file

‎packages/react/src/__tests__/ReactJSXElementValidator-test.js‎

Copy file name to clipboardExpand all lines: packages/react/src/__tests__/ReactJSXElementValidator-test.js
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,4 +417,14 @@ describe('ReactJSXElementValidator', () => {
417417
withoutStack: true,
418418
});
419419
});
420+
421+
it('does not call lazy initializers eagerly', () => {
422+
let didCall = false;
423+
const Lazy = React.lazy(() => {
424+
didCall = true;
425+
return {then() {}};
426+
});
427+
<Lazy />;
428+
expect(didCall).toBe(false);
429+
});
420430
});
Collapse file

‎packages/react/src/jsx/ReactJSXElementValidator.js‎

Copy file name to clipboardExpand all lines: packages/react/src/jsx/ReactJSXElementValidator.js
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ function validatePropTypes(element) {
227227
if (type === null || type === undefined || typeof type === 'string') {
228228
return;
229229
}
230-
const name = getComponentName(type);
231230
let propTypes;
232231
if (typeof type === 'function') {
233232
propTypes = type.propTypes;
@@ -243,9 +242,13 @@ function validatePropTypes(element) {
243242
return;
244243
}
245244
if (propTypes) {
245+
// Intentionally inside to avoid triggering lazy initializers:
246+
const name = getComponentName(type);
246247
checkPropTypes(propTypes, element.props, 'prop', name, element);
247248
} else if (type.PropTypes !== undefined && !propTypesMisspellWarningShown) {
248249
propTypesMisspellWarningShown = true;
250+
// Intentionally inside to avoid triggering lazy initializers:
251+
const name = getComponentName(type);
249252
console.error(
250253
'Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?',
251254
name || 'Unknown',

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.