Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/react-reconciler/src/ReactCurrentFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
HostComponent,
Mode,
LazyComponent,
SuspenseComponent,
} from 'shared/ReactWorkTags';
import describeComponentFrame from 'shared/describeComponentFrame';
import getComponentName from 'shared/getComponentName';
Expand All @@ -33,6 +34,7 @@ function describeFiber(fiber: Fiber): string {
case ClassComponent:
case HostComponent:
case Mode:
case SuspenseComponent:
const owner = fiber._debugOwner;
const source = fiber._debugSource;
const name = getComponentName(fiber.type);
Expand Down
9 changes: 8 additions & 1 deletion packages/react-reconciler/src/ReactFiberUnwindWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
CaptureUpdate,
} from './ReactUpdateQueue';
import {logError} from './ReactFiberCommitWork';
import {getStackByFiberInDevAndProd} from './ReactCurrentFiber';
import {popHostContainer, popHostContext} from './ReactFiberHostContext';
import {
isContextProvider as isLegacyContextProvider,
Expand Down Expand Up @@ -315,8 +316,14 @@ function throwException(
workInProgress = workInProgress.return;
} while (workInProgress !== null);
// No boundary was found. Fallthrough to error mode.
// TODO: Use invariant so the message is stripped in prod?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I originally used invariant inside a try/catch but @sebmarkbage said we should fix our error extraction script to work on Error instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seemsreasonable

value = new Error(
'An update was suspended, but no placeholder UI was provided.',
(getComponentName(sourceFiber.type) || 'A React component') +
' suspended while rendering, but no fallback UI was specified.\n' +
'\n' +
'Add a <Suspense fallback=...> component higher in the tree to ' +
'provide a loading indicator or placeholder to display.' +
getStackByFiberInDevAndProd(sourceFiber),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,19 @@ describe('ReactSuspense', () => {
},
);

expect(root).toFlushAndThrow(
'An update was suspended, but no placeholder UI was provided.',
let err;
try {
root.unstable_flushAll();
} catch (e) {
err = e;
}
expect(err.message.replace(/at .+?:\d+/g, 'at **')).toBe(
'AsyncText suspended while rendering, but no fallback UI was specified.\n' +
'\n' +
'Add a <Suspense fallback=...> component higher in the tree to provide ' +
'a loading indicator or placeholder to display.\n' +
(__DEV__ ? ' in AsyncText (at **)\n' : ' in AsyncText\n') +
(__DEV__ ? ' in Suspense (at **)' : ' in Suspense'),
);
expect(ReactTestRenderer).toHaveYielded(['Suspend! [Hi]', 'Suspend! [Hi]']);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,9 @@ describe('ReactSuspenseWithNoopRenderer', () => {
it('throws a helpful error when an update is suspends without a placeholder', () => {
expect(() => {
ReactNoop.flushSync(() => ReactNoop.render(<AsyncText text="Async" />));
}).toThrow('An update was suspended, but no placeholder UI was provided.');
}).toThrow(
'AsyncText suspended while rendering, but no fallback UI was specified.',
);
});

it('a Suspense component correctly handles more than one suspended child', async () => {
Expand Down