@@ -230,11 +230,17 @@ describe('ReactUse', () => {
230
230
}
231
231
232
232
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
+ } ) ;
236
238
} ) ;
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
+ ] ) ;
238
244
assertLog ( [ 'ABC' ] ) ;
239
245
expect ( root ) . toMatchRenderedOutput ( 'ABC' ) ;
240
246
} ) ;
@@ -394,11 +400,20 @@ describe('ReactUse', () => {
394
400
}
395
401
396
402
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
+ } ) ;
400
408
} ) ;
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
+ ] ) ;
402
417
assertLog ( [
403
418
// First attempt. The uncached promise suspends.
404
419
'Suspend! [Async]' ,
@@ -1733,25 +1748,38 @@ describe('ReactUse', () => {
1733
1748
) ;
1734
1749
} ) ;
1735
1750
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
+ }
1741
1759
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
+ } ) ;
1747
1766
} ) ;
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
+ ) ;
1755
1783
1756
1784
test ( 'warn if async client component calls a hook (e.g. use)' , async ( ) => {
1757
1785
const promise = Promise . resolve ( ) ;
@@ -1769,9 +1797,21 @@ describe('ReactUse', () => {
1769
1797
} ) ;
1770
1798
} ) ;
1771
1799
} ) . 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.' ,
1775
1815
] ) ;
1776
1816
} ) ;
1777
1817
} ) ;
0 commit comments