@@ -230,11 +230,17 @@ describe('ReactUse', () => {
230230 }
231231
232232 const root = ReactNoop . createRoot ( ) ;
233- await act ( ( ) => {
234- startTransition ( ( ) => {
235- root . render ( < App /> ) ;
233+ await expect ( async ( ) => {
234+ await act ( ( ) => {
235+ startTransition ( ( ) => {
236+ root . render ( < App /> ) ;
237+ } ) ;
236238 } ) ;
237- } ) ;
239+ } ) . toErrorDev ( [
240+ 'A component was suspended by an uncached promise. Creating ' +
241+ 'promises inside a Client Component or hook is not yet ' +
242+ 'supported, except via a Suspense-compatible library or framework.' ,
243+ ] ) ;
238244 assertLog ( [ 'ABC' ] ) ;
239245 expect ( root ) . toMatchRenderedOutput ( 'ABC' ) ;
240246 } ) ;
@@ -394,11 +400,20 @@ describe('ReactUse', () => {
394400 }
395401
396402 const root = ReactNoop . createRoot ( ) ;
397- await act ( ( ) => {
398- startTransition ( ( ) => {
399- root . render ( < App /> ) ;
403+ await expect ( async ( ) => {
404+ await act ( ( ) => {
405+ startTransition ( ( ) => {
406+ root . render ( < App /> ) ;
407+ } ) ;
400408 } ) ;
401- } ) ;
409+ } ) . toErrorDev ( [
410+ 'A component was suspended by an uncached promise. Creating ' +
411+ 'promises inside a Client Component or hook is not yet ' +
412+ 'supported, except via a Suspense-compatible library or framework.' ,
413+ 'A component was suspended by an uncached promise. Creating ' +
414+ 'promises inside a Client Component or hook is not yet ' +
415+ 'supported, except via a Suspense-compatible library or framework.' ,
416+ ] ) ;
402417 assertLog ( [
403418 // First attempt. The uncached promise suspends.
404419 'Suspend! [Async]' ,
@@ -1733,25 +1748,38 @@ describe('ReactUse', () => {
17331748 ) ;
17341749 } ) ;
17351750
1736- test ( 'warn if async client component calls a hook (e.g. useState)' , async ( ) => {
1737- async function AsyncClientComponent ( ) {
1738- useState ( ) ;
1739- return < Text text = "Hi" /> ;
1740- }
1751+ test (
1752+ 'warn if async client component calls a hook (e.g. useState) ' +
1753+ 'during a non-sync update' ,
1754+ async ( ) => {
1755+ async function AsyncClientComponent ( ) {
1756+ useState ( ) ;
1757+ return < Text text = "Hi" /> ;
1758+ }
17411759
1742- const root = ReactNoop . createRoot ( ) ;
1743- await expect ( async ( ) => {
1744- await act ( ( ) => {
1745- startTransition ( ( ) => {
1746- root . render ( < AsyncClientComponent /> ) ;
1760+ const root = ReactNoop . createRoot ( ) ;
1761+ await expect ( async ( ) => {
1762+ await act ( ( ) => {
1763+ startTransition ( ( ) => {
1764+ root . render ( < AsyncClientComponent /> ) ;
1765+ } ) ;
17471766 } ) ;
1748- } ) ;
1749- } ) . toErrorDev ( [
1750- 'Hooks are not supported inside an async component. This ' +
1751- "error is often caused by accidentally adding `'use client'` " +
1752- 'to a module that was originally written for the server.' ,
1753- ] ) ;
1754- } ) ;
1767+ } ) . toErrorDev ( [
1768+ // Note: This used to log a different warning about not using hooks
1769+ // inside async components, like we do on the server. Since then, we
1770+ // decided to warn for _any_ async client component regardless of
1771+ // whether the update is sync. But if we ever add back support for async
1772+ // client components, we should add back the hook warning.
1773+ 'async/await is not yet supported in Client Components, only Server ' +
1774+ 'Components. This error is often caused by accidentally adding ' +
1775+ "`'use client'` to a module that was originally written for " +
1776+ 'the server.' ,
1777+ 'A component was suspended by an uncached promise. Creating ' +
1778+ 'promises inside a Client Component or hook is not yet ' +
1779+ 'supported, except via a Suspense-compatible library or framework.' ,
1780+ ] ) ;
1781+ } ,
1782+ ) ;
17551783
17561784 test ( 'warn if async client component calls a hook (e.g. use)' , async ( ) => {
17571785 const promise = Promise . resolve ( ) ;
@@ -1769,9 +1797,21 @@ describe('ReactUse', () => {
17691797 } ) ;
17701798 } ) ;
17711799 } ) . toErrorDev ( [
1772- 'Hooks are not supported inside an async component. This ' +
1773- "error is often caused by accidentally adding `'use client'` " +
1774- 'to a module that was originally written for the server.' ,
1800+ // Note: This used to log a different warning about not using hooks
1801+ // inside async components, like we do on the server. Since then, we
1802+ // decided to warn for _any_ async client component regardless of
1803+ // whether the update is sync. But if we ever add back support for async
1804+ // client components, we should add back the hook warning.
1805+ 'async/await is not yet supported in Client Components, only Server ' +
1806+ 'Components. This error is often caused by accidentally adding ' +
1807+ "`'use client'` to a module that was originally written for " +
1808+ 'the server.' ,
1809+ 'A component was suspended by an uncached promise. Creating ' +
1810+ 'promises inside a Client Component or hook is not yet ' +
1811+ 'supported, except via a Suspense-compatible library or framework.' ,
1812+ 'A component was suspended by an uncached promise. Creating ' +
1813+ 'promises inside a Client Component or hook is not yet ' +
1814+ 'supported, except via a Suspense-compatible library or framework.' ,
17751815 ] ) ;
17761816 } ) ;
17771817} ) ;
0 commit comments