Skip to content

Commit 0592436

Browse files
committed
[Fizz] Current behavior for captureOwnerStack in onError when render is aborted
1 parent b59f186 commit 0592436

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

packages/react-noop-renderer/src/ReactNoopServer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ function render(children: React$Element<any>, options?: Options): Destination {
311311
children,
312312
null,
313313
null,
314+
null,
314315
options ? options.progressiveChunkSize : undefined,
315316
options ? options.onError : undefined,
316317
options ? options.onAllReady : undefined,

packages/react-server/src/__tests__/ReactServer-test.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,28 @@
1010

1111
'use strict';
1212

13+
let act;
1314
let React;
1415
let ReactNoopServer;
1516

17+
function normalizeCodeLocInfo(str) {
18+
return (
19+
str &&
20+
str.replace(/^ +(?:at|in) ([\S]+)[^\n]*/gm, function (m, name) {
21+
const dot = name.lastIndexOf('.');
22+
if (dot !== -1) {
23+
name = name.slice(dot + 1);
24+
}
25+
return ' in ' + name + (/\d/.test(m) ? ' (at **)' : '');
26+
})
27+
);
28+
}
29+
1630
describe('ReactServer', () => {
1731
beforeEach(() => {
1832
jest.resetModules();
1933

34+
act = require('internal-test-utils').act;
2035
React = require('react');
2136
ReactNoopServer = require('react-noop-renderer/server');
2237
});
@@ -32,4 +47,42 @@ describe('ReactServer', () => {
3247
const result = ReactNoopServer.render(<div>hello world</div>);
3348
expect(result.root).toEqual(div('hello world'));
3449
});
50+
51+
it('has Owner Stacks when aborted', async () => {
52+
function Component({promise}) {
53+
React.use(promise);
54+
return <div>Hello, Dave!</div>;
55+
}
56+
function App({promise}) {
57+
return <Component promise={promise} />;
58+
}
59+
60+
let caughtError;
61+
let componentStack;
62+
let ownerStack;
63+
const result = ReactNoopServer.render(
64+
<App promise={new Promise(() => {})} />,
65+
{
66+
onError: (error, errorInfo) => {
67+
caughtError = error;
68+
componentStack = errorInfo.componentStack;
69+
ownerStack = __DEV__ ? React.captureOwnerStack() : null;
70+
},
71+
},
72+
);
73+
74+
await act(async () => {
75+
result.abort();
76+
});
77+
expect(caughtError).toEqual(
78+
expect.objectContaining({
79+
message: 'The render was aborted by the server without a reason.',
80+
}),
81+
);
82+
expect(normalizeCodeLocInfo(componentStack)).toEqual(
83+
'\n in Component (at **)' + '\n in App (at **)',
84+
);
85+
// FIXME: Should have a stack.
86+
expect(normalizeCodeLocInfo(ownerStack)).toEqual(null);
87+
});
3588
});

0 commit comments

Comments
 (0)