Skip to content

Commit fa1a7db

Browse files
committed
Add destructuring to force toObject which throws before the side-effects
This ensures that we don't double call yieldValue or advanceTime in tests. Ideally we could use empty destructuring but ES lint doesn't like it.
1 parent 8be3387 commit fa1a7db

File tree

5 files changed

+48
-47
lines changed

5 files changed

+48
-47
lines changed

packages/react-dom/src/__tests__/ReactDOMServerIntegrationHooks-test.internal.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ describe('ReactDOMServerHooks', () => {
10971097

10981098
it('useOpaqueIdentifier: ID is not used during hydration but is used in an update', async () => {
10991099
let _setShow;
1100-
function App() {
1100+
function App({unused}) {
11011101
Scheduler.unstable_yieldValue('App');
11021102
const id = useOpaqueIdentifier();
11031103
const [show, setShow] = useState(false);
@@ -1129,7 +1129,7 @@ describe('ReactDOMServerHooks', () => {
11291129

11301130
it('useOpaqueIdentifier: ID is not used during hydration but is used in an update in legacy', async () => {
11311131
let _setShow;
1132-
function App() {
1132+
function App({unused}) {
11331133
Scheduler.unstable_yieldValue('App');
11341134
const id = useOpaqueIdentifier();
11351135
const [show, setShow] = useState(false);

packages/react-dom/src/__tests__/ReactErrorBoundaries-test.internal.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -497,18 +497,18 @@ describe('ReactErrorBoundaries', () => {
497497
}
498498
};
499499

500-
BrokenUseEffect = props => {
500+
BrokenUseEffect = ({children}) => {
501501
Scheduler.unstable_yieldValue('BrokenUseEffect render');
502502

503503
React.useEffect(() => {
504504
Scheduler.unstable_yieldValue('BrokenUseEffect useEffect [!]');
505505
throw new Error('Hello');
506506
});
507507

508-
return props.children;
508+
return children;
509509
};
510510

511-
BrokenUseLayoutEffect = props => {
511+
BrokenUseLayoutEffect = ({children}) => {
512512
Scheduler.unstable_yieldValue('BrokenUseLayoutEffect render');
513513

514514
React.useLayoutEffect(() => {
@@ -518,7 +518,7 @@ describe('ReactErrorBoundaries', () => {
518518
throw new Error('Hello');
519519
});
520520

521-
return props.children;
521+
return children;
522522
};
523523

524524
NoopErrorBoundary = class extends React.Component {

packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.internal.js

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,17 @@ describe('ReactIncrementalErrorHandling', () => {
6262
}
6363
}
6464

65-
function ErrorMessage(props) {
65+
function ErrorMessage({error}) {
6666
Scheduler.unstable_yieldValue('ErrorMessage');
67-
return <span prop={`Caught an error: ${props.error.message}`} />;
67+
return <span prop={`Caught an error: ${error.message}`} />;
6868
}
6969

70-
function Indirection(props) {
70+
function Indirection({children}) {
7171
Scheduler.unstable_yieldValue('Indirection');
72-
return props.children || null;
72+
return children || null;
7373
}
7474

75-
function BadRender() {
75+
function BadRender({unused}) {
7676
Scheduler.unstable_yieldValue('throw');
7777
throw new Error('oops!');
7878
}
@@ -156,17 +156,17 @@ describe('ReactIncrementalErrorHandling', () => {
156156
}
157157
}
158158

159-
function ErrorMessage(props) {
159+
function ErrorMessage({error}) {
160160
Scheduler.unstable_yieldValue('ErrorMessage');
161-
return <span prop={`Caught an error: ${props.error.message}`} />;
161+
return <span prop={`Caught an error: ${error.message}`} />;
162162
}
163163

164-
function Indirection(props) {
164+
function Indirection({children}) {
165165
Scheduler.unstable_yieldValue('Indirection');
166-
return props.children || null;
166+
return children || null;
167167
}
168168

169-
function BadRender() {
169+
function BadRender({unused}) {
170170
Scheduler.unstable_yieldValue('throw');
171171
throw new Error('oops!');
172172
}
@@ -346,17 +346,17 @@ describe('ReactIncrementalErrorHandling', () => {
346346
});
347347

348348
it('retries one more time before handling error', () => {
349-
function BadRender() {
349+
function BadRender({unused}) {
350350
Scheduler.unstable_yieldValue('BadRender');
351351
throw new Error('oops');
352352
}
353353

354-
function Sibling() {
354+
function Sibling({unused}) {
355355
Scheduler.unstable_yieldValue('Sibling');
356356
return <span prop="Sibling" />;
357357
}
358358

359-
function Parent() {
359+
function Parent({unused}) {
360360
Scheduler.unstable_yieldValue('Parent');
361361
return (
362362
<>
@@ -386,7 +386,7 @@ describe('ReactIncrementalErrorHandling', () => {
386386
});
387387

388388
it('retries one more time if an error occurs during a render that expires midway through the tree', () => {
389-
function Oops() {
389+
function Oops({unused}) {
390390
Scheduler.unstable_yieldValue('Oops');
391391
throw new Error('Oops');
392392
}
@@ -396,7 +396,7 @@ describe('ReactIncrementalErrorHandling', () => {
396396
return text;
397397
}
398398

399-
function App() {
399+
function App({unused}) {
400400
return (
401401
<>
402402
<Text text="A" />
@@ -530,7 +530,7 @@ describe('ReactIncrementalErrorHandling', () => {
530530
}
531531
}
532532

533-
function BrokenRender(props) {
533+
function BrokenRender({unused}) {
534534
Scheduler.unstable_yieldValue('BrokenRender');
535535
throw new Error('Hello');
536536
}
@@ -576,7 +576,7 @@ describe('ReactIncrementalErrorHandling', () => {
576576
}
577577
}
578578

579-
function BrokenRender(props) {
579+
function BrokenRender({unused}) {
580580
Scheduler.unstable_yieldValue('BrokenRender');
581581
throw new Error('Hello');
582582
}
@@ -623,7 +623,7 @@ describe('ReactIncrementalErrorHandling', () => {
623623
}
624624
}
625625

626-
function BrokenRender(props) {
626+
function BrokenRender({unused}) {
627627
Scheduler.unstable_yieldValue('BrokenRender');
628628
throw new Error('Hello');
629629
}
@@ -664,7 +664,7 @@ describe('ReactIncrementalErrorHandling', () => {
664664
}
665665
}
666666

667-
function BrokenRender() {
667+
function BrokenRender({unused}) {
668668
Scheduler.unstable_yieldValue('BrokenRender');
669669
throw new Error('Hello');
670670
}
@@ -703,7 +703,7 @@ describe('ReactIncrementalErrorHandling', () => {
703703
}
704704
}
705705

706-
function BrokenRender() {
706+
function BrokenRender({unused}) {
707707
Scheduler.unstable_yieldValue('BrokenRender');
708708
throw new Error('Hello');
709709
}
@@ -744,7 +744,7 @@ describe('ReactIncrementalErrorHandling', () => {
744744
}
745745
}
746746

747-
function BrokenRender() {
747+
function BrokenRender({unused}) {
748748
Scheduler.unstable_yieldValue('BrokenRender');
749749
throw new Error('Hello');
750750
}
@@ -784,7 +784,7 @@ describe('ReactIncrementalErrorHandling', () => {
784784
}
785785
}
786786

787-
function BrokenRender() {
787+
function BrokenRender({unused}) {
788788
Scheduler.unstable_yieldValue('BrokenRender');
789789
throw new Error('Hello');
790790
}
@@ -862,12 +862,12 @@ describe('ReactIncrementalErrorHandling', () => {
862862
});
863863

864864
it('can schedule updates after uncaught error in render on mount', () => {
865-
function BrokenRender() {
865+
function BrokenRender({unused}) {
866866
Scheduler.unstable_yieldValue('BrokenRender');
867867
throw new Error('Hello');
868868
}
869869

870-
function Foo() {
870+
function Foo({unused}) {
871871
Scheduler.unstable_yieldValue('Foo');
872872
return null;
873873
}
@@ -887,24 +887,24 @@ describe('ReactIncrementalErrorHandling', () => {
887887
});
888888

889889
it('can schedule updates after uncaught error in render on update', () => {
890-
function BrokenRender(props) {
890+
function BrokenRender({shouldThrow}) {
891891
Scheduler.unstable_yieldValue('BrokenRender');
892-
if (props.throw) {
892+
if (shouldThrow) {
893893
throw new Error('Hello');
894894
}
895895
return null;
896896
}
897897

898-
function Foo() {
898+
function Foo({unused}) {
899899
Scheduler.unstable_yieldValue('Foo');
900900
return null;
901901
}
902902

903-
ReactNoop.render(<BrokenRender throw={false} />);
903+
ReactNoop.render(<BrokenRender shouldThrow={false} />);
904904
expect(Scheduler).toFlushAndYield(['BrokenRender']);
905905

906906
expect(() => {
907-
ReactNoop.render(<BrokenRender throw={true} />);
907+
ReactNoop.render(<BrokenRender shouldThrow={true} />);
908908
expect(Scheduler).toFlushWithoutYielding();
909909
}).toThrow('Hello');
910910
expect(Scheduler).toHaveYielded([
@@ -1454,13 +1454,13 @@ describe('ReactIncrementalErrorHandling', () => {
14541454
}
14551455
}
14561456

1457-
function Indirection(props) {
1457+
function Indirection({children}) {
14581458
Scheduler.unstable_yieldValue('Indirection');
1459-
return props.children;
1459+
return children;
14601460
}
14611461

14621462
const notAnError = {nonStandardMessage: 'oops'};
1463-
function BadRender() {
1463+
function BadRender({unused}) {
14641464
Scheduler.unstable_yieldValue('BadRender');
14651465
throw notAnError;
14661466
}
@@ -1519,17 +1519,17 @@ describe('ReactIncrementalErrorHandling', () => {
15191519
}
15201520
}
15211521

1522-
function ErrorMessage(props) {
1522+
function ErrorMessage({error}) {
15231523
Scheduler.unstable_yieldValue('ErrorMessage');
1524-
return <span prop={`Caught an error: ${props.error.message}`} />;
1524+
return <span prop={`Caught an error: ${error.message}`} />;
15251525
}
15261526

1527-
function BadRenderSibling(props) {
1527+
function BadRenderSibling({unused}) {
15281528
Scheduler.unstable_yieldValue('BadRenderSibling');
15291529
return null;
15301530
}
15311531

1532-
function BadRender() {
1532+
function BadRender({unused}) {
15331533
Scheduler.unstable_yieldValue('throw');
15341534
throw new Error('oops!');
15351535
}
@@ -1567,7 +1567,7 @@ describe('ReactIncrementalErrorHandling', () => {
15671567
// This test seems a bit contrived, but it's based on an actual regression
15681568
// where we checked for the existence of didUpdate instead of didMount, and
15691569
// didMount was not defined.
1570-
function BadRender() {
1570+
function BadRender({unused}) {
15711571
Scheduler.unstable_yieldValue('throw');
15721572
throw new Error('oops!');
15731573
}
@@ -1711,7 +1711,7 @@ describe('ReactIncrementalErrorHandling', () => {
17111711
it('uncaught errors should be discarded if the render is aborted', async () => {
17121712
const root = ReactNoop.createRoot();
17131713

1714-
function Oops() {
1714+
function Oops({unused}) {
17151715
Scheduler.unstable_yieldValue('Oops');
17161716
throw Error('Oops');
17171717
}

packages/react/src/__tests__/ReactProfiler-test.internal.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ describe('Profiler', () => {
10411041
it('should accumulate actual time after an error handled by componentDidCatch()', () => {
10421042
const callback = jest.fn();
10431043

1044-
const ThrowsError = () => {
1044+
const ThrowsError = ({unused}) => {
10451045
Scheduler.unstable_advanceTime(3);
10461046
throw Error('expected error');
10471047
};
@@ -1120,7 +1120,7 @@ describe('Profiler', () => {
11201120
it('should accumulate actual time after an error handled by getDerivedStateFromError()', () => {
11211121
const callback = jest.fn();
11221122

1123-
const ThrowsError = () => {
1123+
const ThrowsError = ({unused}) => {
11241124
Scheduler.unstable_advanceTime(10);
11251125
throw Error('expected error');
11261126
};

packages/react/src/__tests__/forwardRef-test.internal.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,9 @@ describe('forwardRef', () => {
159159
}
160160

161161
function Wrapper(props) {
162+
const forwardedRef = props.forwardedRef;
162163
Scheduler.unstable_yieldValue('Wrapper');
163-
return <BadRender {...props} ref={props.forwardedRef} />;
164+
return <BadRender {...props} ref={forwardedRef} />;
164165
}
165166

166167
const RefForwardingComponent = React.forwardRef((props, ref) => (

0 commit comments

Comments
 (0)