Skip to content

Commit e791570

Browse files
committed
Tweak error message for missing fallback
1 parent 595b4f9 commit e791570

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

packages/react-reconciler/src/ReactCurrentFiber.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
HostComponent,
1818
Mode,
1919
LazyComponent,
20+
SuspenseComponent,
2021
} from 'shared/ReactWorkTags';
2122
import describeComponentFrame from 'shared/describeComponentFrame';
2223
import getComponentName from 'shared/getComponentName';
@@ -33,6 +34,7 @@ function describeFiber(fiber: Fiber): string {
3334
case ClassComponent:
3435
case HostComponent:
3536
case Mode:
37+
case SuspenseComponent:
3638
const owner = fiber._debugOwner;
3739
const source = fiber._debugSource;
3840
const name = getComponentName(fiber.type);

packages/react-reconciler/src/ReactFiberUnwindWork.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
CaptureUpdate,
4747
} from './ReactUpdateQueue';
4848
import {logError} from './ReactFiberCommitWork';
49+
import {getStackByFiberInDevAndProd} from './ReactCurrentFiber';
4950
import {popHostContainer, popHostContext} from './ReactFiberHostContext';
5051
import {
5152
isContextProvider as isLegacyContextProvider,
@@ -315,8 +316,14 @@ function throwException(
315316
workInProgress = workInProgress.return;
316317
} while (workInProgress !== null);
317318
// No boundary was found. Fallthrough to error mode.
319+
// TODO: Use invariant so the message is stripped in prod?
318320
value = new Error(
319-
'An update was suspended, but no placeholder UI was provided.',
321+
(getComponentName(sourceFiber.type) || 'A React component') +
322+
' suspended while rendering, but no fallback UI was specified.\n' +
323+
'\n' +
324+
'Add a <Suspense fallback=...> component higher in the tree to ' +
325+
'provide a loading indicator or placeholder to display.' +
326+
getStackByFiberInDevAndProd(sourceFiber),
320327
);
321328
}
322329

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,19 @@ describe('ReactSuspense', () => {
312312
},
313313
);
314314

315-
expect(root).toFlushAndThrow(
316-
'An update was suspended, but no placeholder UI was provided.',
315+
let err;
316+
try {
317+
root.unstable_flushAll();
318+
} catch (e) {
319+
err = e;
320+
}
321+
expect(err.message.replace(/at .+?:\d+/g, 'at **')).toBe(
322+
'AsyncText suspended while rendering, but no fallback UI was specified.\n' +
323+
'\n' +
324+
'Add a <Suspense fallback=...> component higher in the tree to provide ' +
325+
'a loading indicator or placeholder to display.\n' +
326+
' in AsyncText (at **)\n' +
327+
' in Suspense (at **)',
317328
);
318329
expect(ReactTestRenderer).toHaveYielded(['Suspend! [Hi]', 'Suspend! [Hi]']);
319330
});

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,9 @@ describe('ReactSuspenseWithNoopRenderer', () => {
652652
it('throws a helpful error when an update is suspends without a placeholder', () => {
653653
expect(() => {
654654
ReactNoop.flushSync(() => ReactNoop.render(<AsyncText text="Async" />));
655-
}).toThrow('An update was suspended, but no placeholder UI was provided.');
655+
}).toThrow(
656+
'AsyncText suspended while rendering, but no fallback UI was specified.',
657+
);
656658
});
657659

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

0 commit comments

Comments
 (0)