10
11
'use strict';
12
13
+let ReactFeatureFlags = require('shared/ReactFeatureFlags');
14
let PropTypes;
14
-let ReactFeatureFlags;
15
let React;
16
let ReactNoop;
17
let Scheduler;
37
}
38
39
function normalizeCodeLocInfo(str) {
40
- return str && str.replace(/\(at .+?:\d+\)/g, '(at **)');
40
+ return (
41
+ str &&
42
+ str.replace(/\n +(?:at|in) ([\S]+)[^\n]*/g, function(m, name) {
43
+ return '\n in ' + name + ' (at **)';
44
+ })
45
+ );
46
}
47
48
it('recovers from errors asynchronously', () => {
62
}
63
}
64
60
- function ErrorMessage(props) {
65
+ function ErrorMessage({error}) {
66
Scheduler.unstable_yieldValue('ErrorMessage');
62
- return <span prop={`Caught an error: ${props.error.message}`} />;
67
+ return <span prop={`Caught an error: ${error.message}`} />;
68
}
69
65
- function Indirection(props) {
70
+ function Indirection({children}) {
71
Scheduler.unstable_yieldValue('Indirection');
67
- return props.children || null;
72
+ return children || null;
73
}
74
70
- function BadRender() {
75
+ function BadRender({unused}) {
76
Scheduler.unstable_yieldValue('throw');
77
throw new Error('oops!');
78
}
156
}
157
}
158
154
- function ErrorMessage(props) {
159
+ function ErrorMessage({error}) {
160
Scheduler.unstable_yieldValue('ErrorMessage');
156
- return <span prop={`Caught an error: ${props.error.message}`} />;
161
+ return <span prop={`Caught an error: ${error.message}`} />;
162
}
163
159
- function Indirection(props) {
164
+ function Indirection({children}) {
165
Scheduler.unstable_yieldValue('Indirection');
161
- return props.children || null;
166
+ return children || null;
167
}
168
164
- function BadRender() {
169
+ function BadRender({unused}) {
170
Scheduler.unstable_yieldValue('throw');
171
throw new Error('oops!');
172
}
346
});
347
348
it('retries one more time before handling error', () => {
344
- function BadRender() {
349
+ function BadRender({unused}) {
350
Scheduler.unstable_yieldValue('BadRender');
351
throw new Error('oops');
352
}
353
349
- function Sibling() {
354
+ function Sibling({unused}) {
355
Scheduler.unstable_yieldValue('Sibling');
356
return <span prop="Sibling" />;
357
}
358
354
- function Parent() {
359
+ function Parent({unused}) {
360
Scheduler.unstable_yieldValue('Parent');
361
return (
362
<>
386
});
387
388
it('retries one more time if an error occurs during a render that expires midway through the tree', () => {
384
- function Oops() {
389
+ function Oops({unused}) {
390
Scheduler.unstable_yieldValue('Oops');
391
throw new Error('Oops');
392
}
396
return text;
397
}
398
394
- function App() {
399
+ function App({unused}) {
400
return (
401
<>
402
<Text text="A" />
530
}
531
}
532
528
- function BrokenRender(props) {
533
+ function BrokenRender({unused}) {
534
Scheduler.unstable_yieldValue('BrokenRender');
535
throw new Error('Hello');
536
}
576
}
577
}
578
574
- function BrokenRender(props) {
579
+ function BrokenRender({unused}) {
580
Scheduler.unstable_yieldValue('BrokenRender');
581
throw new Error('Hello');
582
}
623
}
624
}
625
621
- function BrokenRender(props) {
626
+ function BrokenRender({unused}) {
627
Scheduler.unstable_yieldValue('BrokenRender');
628
throw new Error('Hello');
629
}
664
}
665
}
666
662
- function BrokenRender() {
667
+ function BrokenRender({unused}) {
668
Scheduler.unstable_yieldValue('BrokenRender');
669
throw new Error('Hello');
670
}
703
}
704
}
705
701
- function BrokenRender() {
706
+ function BrokenRender({unused}) {
707
Scheduler.unstable_yieldValue('BrokenRender');
708
throw new Error('Hello');
709
}
744
}
745
}
746
742
- function BrokenRender() {
747
+ function BrokenRender({unused}) {
748
Scheduler.unstable_yieldValue('BrokenRender');
749
throw new Error('Hello');
750
}
784
}
785
}
786
782
- function BrokenRender() {
787
+ function BrokenRender({unused}) {
788
Scheduler.unstable_yieldValue('BrokenRender');
789
throw new Error('Hello');
790
}
862
});
863
864
it('can schedule updates after uncaught error in render on mount', () => {
860
- function BrokenRender() {
865
+ function BrokenRender({unused}) {
866
Scheduler.unstable_yieldValue('BrokenRender');
867
throw new Error('Hello');
868
}
869
865
- function Foo() {
870
+ function Foo({unused}) {
871
Scheduler.unstable_yieldValue('Foo');
872
return null;
873
}
887
});
888
889
it('can schedule updates after uncaught error in render on update', () => {
885
- function BrokenRender(props) {
890
+ function BrokenRender({shouldThrow}) {
891
Scheduler.unstable_yieldValue('BrokenRender');
887
- if (props.throw) {
892
+ if (shouldThrow) {
893
throw new Error('Hello');
894
}
895
return null;
896
}
897
893
- function Foo() {
898
+ function Foo({unused}) {
899
Scheduler.unstable_yieldValue('Foo');
900
return null;
901
}
902
898
- ReactNoop.render(<BrokenRender throw={false} />);
903
+ ReactNoop.render(<BrokenRender shouldThrow={false} />);
904
expect(Scheduler).toFlushAndYield(['BrokenRender']);
905
906
expect(() => {
902
- ReactNoop.render(<BrokenRender throw={true} />);
907
+ ReactNoop.render(<BrokenRender shouldThrow={true} />);
908
expect(Scheduler).toFlushWithoutYielding();
909
}).toThrow('Hello');
910
expect(Scheduler).toHaveYielded([
1454
}
1455
}
1456
1452
- function Indirection(props) {
1457
+ function Indirection({children}) {
1458
Scheduler.unstable_yieldValue('Indirection');
1454
- return props.children;
1459
+ return children;
1460
}
1461
1462
const notAnError = {nonStandardMessage: 'oops'};
1458
- function BadRender() {
1463
+ function BadRender({unused}) {
1464
Scheduler.unstable_yieldValue('BadRender');
1465
throw notAnError;
1466
}
1519
}
1520
}
1521
1517
- function ErrorMessage(props) {
1522
+ function ErrorMessage({error}) {
1523
Scheduler.unstable_yieldValue('ErrorMessage');
1519
- return <span prop={`Caught an error: ${props.error.message}`} />;
1524
+ return <span prop={`Caught an error: ${error.message}`} />;
1525
}
1526
1522
- function BadRenderSibling(props) {
1527
+ function BadRenderSibling({unused}) {
1528
Scheduler.unstable_yieldValue('BadRenderSibling');
1529
return null;
1530
}
1531
1527
- function BadRender() {
1532
+ function BadRender({unused}) {
1533
Scheduler.unstable_yieldValue('throw');
1534
throw new Error('oops!');
1535
}
1567
// This test seems a bit contrived, but it's based on an actual regression
1568
// where we checked for the existence of didUpdate instead of didMount, and
1569
// didMount was not defined.
1565
- function BadRender() {
1570
+ function BadRender({unused}) {
1571
Scheduler.unstable_yieldValue('throw');
1572
throw new Error('oops!');
1573
}
1638
expect(ReactNoop.getChildren()).toEqual([
1639
span(
1640
'Caught an error:\n' +
1636
- (__DEV__
1637
- ? ' in BrokenRender (at **)\n'
1638
- : ' in BrokenRender\n') +
1639
- (__DEV__ ? ' in ErrorBoundary (at **).' : ' in ErrorBoundary.'),
1641
+ ' in BrokenRender (at **)\n' +
1642
+ ' in ErrorBoundary (at **).',
1643
),
1644
]);
1645
});
1672
expect(ReactNoop.getChildren()).toEqual([span('Caught an error: Hello')]);
1673
});
1674
1672
- if (!require('shared/ReactFeatureFlags').disableModulePatternComponents) {
1675
+ if (!ReactFeatureFlags.disableModulePatternComponents) {
1676
it('handles error thrown inside getDerivedStateFromProps of a module-style context provider', () => {
1677
function Provider() {
1678
return {
1711
it('uncaught errors should be discarded if the render is aborted', async () => {
1712
const root = ReactNoop.createRoot();
1713
1711
- function Oops() {
1714
+ function Oops({unused}) {
1715
Scheduler.unstable_yieldValue('Oops');
1716
throw Error('Oops');
1717
}