@@ -1786,4 +1786,114 @@ describe('ReactCompositeComponent', () => {
1786
1786
ReactDOM . render ( < Shadow /> , container ) ;
1787
1787
expect ( container . firstChild . tagName ) . toBe ( 'DIV' ) ;
1788
1788
} ) ;
1789
+
1790
+ it ( 'should not warn on updating function component from componentWillMount' , ( ) => {
1791
+ let _setState ;
1792
+ function A ( ) {
1793
+ _setState = React . useState ( ) [ 1 ] ;
1794
+ return null ;
1795
+ }
1796
+ class B extends React . Component {
1797
+ UNSAFE_componentWillMount ( ) {
1798
+ _setState ( { } ) ;
1799
+ }
1800
+ render ( ) {
1801
+ return null ;
1802
+ }
1803
+ }
1804
+ function Parent ( ) {
1805
+ return (
1806
+ < div >
1807
+ < A />
1808
+ < B />
1809
+ </ div >
1810
+ ) ;
1811
+ }
1812
+ const container = document . createElement ( 'div' ) ;
1813
+ ReactDOM . render ( < Parent /> , container ) ;
1814
+ } ) ;
1815
+
1816
+ it ( 'should not warn on updating function component from componentWillUpdate' , ( ) => {
1817
+ let _setState ;
1818
+ function A ( ) {
1819
+ _setState = React . useState ( ) [ 1 ] ;
1820
+ return null ;
1821
+ }
1822
+ class B extends React . Component {
1823
+ UNSAFE_componentWillUpdate ( ) {
1824
+ _setState ( { } ) ;
1825
+ }
1826
+ render ( ) {
1827
+ return null ;
1828
+ }
1829
+ }
1830
+ function Parent ( ) {
1831
+ return (
1832
+ < div >
1833
+ < A />
1834
+ < B />
1835
+ </ div >
1836
+ ) ;
1837
+ }
1838
+ const container = document . createElement ( 'div' ) ;
1839
+ ReactDOM . render ( < Parent /> , container ) ;
1840
+ ReactDOM . render ( < Parent /> , container ) ;
1841
+ } ) ;
1842
+
1843
+ it ( 'should not warn on updating function component from componentWillReceiveProps' , ( ) => {
1844
+ let _setState ;
1845
+ function A ( ) {
1846
+ _setState = React . useState ( ) [ 1 ] ;
1847
+ return null ;
1848
+ }
1849
+ class B extends React . Component {
1850
+ UNSAFE_componentWillReceiveProps ( ) {
1851
+ _setState ( { } ) ;
1852
+ }
1853
+ render ( ) {
1854
+ return null ;
1855
+ }
1856
+ }
1857
+ function Parent ( ) {
1858
+ return (
1859
+ < div >
1860
+ < A />
1861
+ < B />
1862
+ </ div >
1863
+ ) ;
1864
+ }
1865
+ const container = document . createElement ( 'div' ) ;
1866
+ ReactDOM . render ( < Parent /> , container ) ;
1867
+ ReactDOM . render ( < Parent /> , container ) ;
1868
+ } ) ;
1869
+
1870
+ it ( 'should warn on updating function component from render' , ( ) => {
1871
+ let _setState ;
1872
+ function A ( ) {
1873
+ _setState = React . useState ( ) [ 1 ] ;
1874
+ return null ;
1875
+ }
1876
+ class B extends React . Component {
1877
+ render ( ) {
1878
+ _setState ( { } ) ;
1879
+ return null ;
1880
+ }
1881
+ }
1882
+ function Parent ( ) {
1883
+ return (
1884
+ < div >
1885
+ < A />
1886
+ < B />
1887
+ </ div >
1888
+ ) ;
1889
+ }
1890
+ const container = document . createElement ( 'div' ) ;
1891
+ expect ( ( ) => {
1892
+ ReactDOM . render ( < Parent /> , container ) ;
1893
+ } ) . toErrorDev (
1894
+ 'Cannot update a component (`A`) while rendering a different component (`B`)' ,
1895
+ ) ;
1896
+ // Dedupe.
1897
+ ReactDOM . render ( < Parent /> , container ) ;
1898
+ } ) ;
1789
1899
} ) ;
0 commit comments