Skip to content

Commit c58ffc4

Browse files
committed
Include component name in "async/await is not supported" error message if available
1 parent ed8b68d commit c58ffc4

File tree

4 files changed

+39
-23
lines changed

4 files changed

+39
-23
lines changed

packages/react-reconciler/src/ReactFiberHooks.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,13 @@ function warnIfAsyncClientComponent(Component: Function) {
461461
if (!didWarnAboutAsyncClientComponent.has(componentName)) {
462462
didWarnAboutAsyncClientComponent.add(componentName);
463463
console.error(
464-
'async/await is not yet supported in Client Components, only ' +
465-
'Server Components. This error is often caused by accidentally ' +
464+
'%s is an async/await Client Component. ' +
465+
'Only Server Components can be async at the moment. This error is often caused by accidentally ' +
466466
"adding `'use client'` to a module that was originally written " +
467467
'for the server.',
468+
componentName === null
469+
? 'An unknown Component'
470+
: `<${componentName}>`,
468471
);
469472
}
470473
}

packages/react-reconciler/src/ReactFiberThenable.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,9 @@ export function trackUsedThenable<T>(
194194
// this case include forcing a concurrent render, or putting the whole
195195
// root into offscreen mode.
196196
throw new Error(
197-
'async/await is not yet supported in Client Components, only ' +
198-
'Server Components. This error is often caused by accidentally ' +
197+
'An unknown Component is an async Client Component. ' +
198+
'Only Server Components can be async at the moment. ' +
199+
'This error is often caused by accidentally ' +
199200
"adding `'use client'` to a module that was originally written " +
200201
'for the server.',
201202
);

packages/react-reconciler/src/__tests__/ReactUse-test.js

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,8 @@ describe('ReactUse', () => {
14431443
});
14441444
assertLog(['A', 'Mount: A']);
14451445
assertConsoleErrorDev([
1446-
'async/await is not yet supported in Client Components, only Server Components. ' +
1446+
'<App> is an async/await Client Component. ' +
1447+
'Only Server Components can be async at the moment. ' +
14471448
"This error is often caused by accidentally adding `'use client'` " +
14481449
'to a module that was originally written for the server.\n' +
14491450
' in App (at **)',
@@ -1915,25 +1916,29 @@ describe('ReactUse', () => {
19151916
);
19161917
});
19171918
assertConsoleErrorDev([
1918-
'async/await is not yet supported in Client Components, only Server Components. ' +
1919+
'<AsyncClientComponent> is an async/await Client Component. ' +
1920+
'Only Server Components can be async at the moment. ' +
19191921
"This error is often caused by accidentally adding `'use client'` " +
19201922
'to a module that was originally written for the server.\n' +
19211923
' in AsyncClientComponent (at **)' +
19221924
(gate('enableOwnerStacks') ? '' : '\n in ErrorBoundary (at **)'),
19231925
]);
19241926
assertLog([
1925-
'async/await is not yet supported in Client Components, only Server ' +
1926-
'Components. This error is often caused by accidentally adding ' +
1927+
'An unknown Component is an async Client Component. ' +
1928+
'Only Server Components can be async at the moment. ' +
1929+
'This error is often caused by accidentally adding ' +
19271930
"`'use client'` to a module that was originally written for " +
19281931
'the server.',
1929-
'async/await is not yet supported in Client Components, only Server ' +
1930-
'Components. This error is often caused by accidentally adding ' +
1932+
'An unknown Component is an async Client Component. ' +
1933+
'Only Server Components can be async at the moment. ' +
1934+
'This error is often caused by accidentally adding ' +
19311935
"`'use client'` to a module that was originally written for " +
19321936
'the server.',
19331937
]);
19341938
expect(root).toMatchRenderedOutput(
1935-
'async/await is not yet supported in Client Components, only Server ' +
1936-
'Components. This error is often caused by accidentally adding ' +
1939+
'An unknown Component is an async Client Component. ' +
1940+
'Only Server Components can be async at the moment. ' +
1941+
'This error is often caused by accidentally adding ' +
19371942
"`'use client'` to a module that was originally written for " +
19381943
'the server.',
19391944
);
@@ -1967,25 +1972,29 @@ describe('ReactUse', () => {
19671972
);
19681973
});
19691974
assertConsoleErrorDev([
1970-
'async/await is not yet supported in Client Components, only Server Components. ' +
1975+
'<AsyncClientComponent> is an async/await Client Component. ' +
1976+
'Only Server Components can be async at the moment. ' +
19711977
"This error is often caused by accidentally adding `'use client'` " +
19721978
'to a module that was originally written for the server.\n' +
19731979
' in AsyncClientComponent (at **)' +
19741980
(gate('enableOwnerStacks') ? '' : '\n in ErrorBoundary (at **)'),
19751981
]);
19761982
assertLog([
1977-
'async/await is not yet supported in Client Components, only Server ' +
1978-
'Components. This error is often caused by accidentally adding ' +
1983+
'An unknown Component is an async Client Component. ' +
1984+
'Only Server Components can be async at the moment. ' +
1985+
'This error is often caused by accidentally adding ' +
19791986
"`'use client'` to a module that was originally written for " +
19801987
'the server.',
1981-
'async/await is not yet supported in Client Components, only Server ' +
1982-
'Components. This error is often caused by accidentally adding ' +
1988+
'An unknown Component is an async Client Component. ' +
1989+
'Only Server Components can be async at the moment. ' +
1990+
'This error is often caused by accidentally adding ' +
19831991
"`'use client'` to a module that was originally written for " +
19841992
'the server.',
19851993
]);
19861994
expect(root).toMatchRenderedOutput(
1987-
'async/await is not yet supported in Client Components, only Server ' +
1988-
'Components. This error is often caused by accidentally adding ' +
1995+
'An unknown Component is an async Client Component. ' +
1996+
'Only Server Components can be async at the moment. ' +
1997+
'This error is often caused by accidentally adding ' +
19891998
"`'use client'` to a module that was originally written for " +
19901999
'the server.',
19912000
);
@@ -2012,7 +2021,8 @@ describe('ReactUse', () => {
20122021
// decided to warn for _any_ async client component regardless of
20132022
// whether the update is sync. But if we ever add back support for async
20142023
// client components, we should add back the hook warning.
2015-
'async/await is not yet supported in Client Components, only Server Components. ' +
2024+
'<AsyncClientComponent> is an async/await Client Component. ' +
2025+
'Only Server Components can be async at the moment. ' +
20162026
"This error is often caused by accidentally adding `'use client'` " +
20172027
'to a module that was originally written for the server.\n' +
20182028
' in AsyncClientComponent (at **)',
@@ -2044,7 +2054,8 @@ describe('ReactUse', () => {
20442054
// decided to warn for _any_ async client component regardless of
20452055
// whether the update is sync. But if we ever add back support for async
20462056
// client components, we should add back the hook warning.
2047-
'async/await is not yet supported in Client Components, only Server Components. ' +
2057+
'<AsyncClientComponent> is an async/await Client Component. ' +
2058+
'Only Server Components can be async at the moment. ' +
20482059
"This error is often caused by accidentally adding `'use client'` " +
20492060
'to a module that was originally written for the server.\n' +
20502061
' in AsyncClientComponent (at **)',
@@ -2079,7 +2090,8 @@ describe('ReactUse', () => {
20792090
});
20802091
});
20812092
assertConsoleErrorDev([
2082-
'async/await is not yet supported in Client Components, only Server Components. ' +
2093+
'<App> is an async/await Client Component. ' +
2094+
'Only Server Components can be async at the moment. ' +
20832095
"This error is often caused by accidentally adding `'use client'` " +
20842096
'to a module that was originally written for the server.\n' +
20852097
' in App (at **)',

scripts/error-codes/codes.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@
467467
"479": "Cannot update optimistic state while rendering.",
468468
"480": "File/Blob fields are not yet supported in progressive forms. Will fallback to client hydration.",
469469
"481": "Tried to encode a Server Action from a different instance than the encoder is from. This is a bug in React.",
470-
"482": "async/await is not yet supported in Client Components, only Server Components. This error is often caused by accidentally adding `'use client'` to a module that was originally written for the server.",
470+
"482": "An unknown Component is an async Client Component. Only Server Components can be async at the moment. This error is often caused by accidentally adding `'use client'` to a module that was originally written for the server.",
471471
"483": "Hooks are not supported inside an async component. This error is often caused by accidentally adding `'use client'` to a module that was originally written for the server.",
472472
"484": "A Server Component was postponed. The reason is omitted in production builds to avoid leaking sensitive details.",
473473
"485": "Cannot update form state while rendering.",

0 commit comments

Comments
 (0)