@@ -1613,6 +1613,115 @@ describe('FragmentRefs', () => {
16131613 ) ;
16141614 } ) ;
16151615
1616+ it ( 'compares a root-level Fragment' , async ( ) => {
1617+ const fragmentRef = React . createRef ( ) ;
1618+ const emptyFragmentRef = React . createRef ( ) ;
1619+ const childRef = React . createRef ( ) ;
1620+ const siblingPrecedingRef = React . createRef ( ) ;
1621+ const siblingFollowingRef = React . createRef ( ) ;
1622+ const root = ReactDOMClient . createRoot ( container ) ;
1623+
1624+ function Test ( ) {
1625+ return (
1626+ < Fragment >
1627+ < div ref = { siblingPrecedingRef } />
1628+ < Fragment ref = { fragmentRef } >
1629+ < div ref = { childRef } />
1630+ </ Fragment >
1631+ < Fragment ref = { emptyFragmentRef } />
1632+ < div ref = { siblingFollowingRef } />
1633+ </ Fragment >
1634+ ) ;
1635+ }
1636+
1637+ await act ( ( ) => root . render ( < Test /> ) ) ;
1638+
1639+ const fragmentInstance = fragmentRef . current ;
1640+ if ( fragmentInstance == null ) {
1641+ throw new Error ( 'Expected fragment instance to be non-null' ) ;
1642+ }
1643+ const emptyFragmentInstance = emptyFragmentRef . current ;
1644+ if ( emptyFragmentInstance == null ) {
1645+ throw new Error ( 'Expected empty fragment instance to be non-null' ) ;
1646+ }
1647+
1648+ expectPosition (
1649+ fragmentInstance . compareDocumentPosition ( childRef . current ) ,
1650+ {
1651+ preceding : false ,
1652+ following : false ,
1653+ contains : false ,
1654+ containedBy : true ,
1655+ disconnected : false ,
1656+ implementationSpecific : false ,
1657+ } ,
1658+ ) ;
1659+
1660+ expectPosition (
1661+ fragmentInstance . compareDocumentPosition ( siblingPrecedingRef . current ) ,
1662+ {
1663+ preceding : true ,
1664+ following : false ,
1665+ contains : false ,
1666+ containedBy : false ,
1667+ disconnected : false ,
1668+ implementationSpecific : false ,
1669+ } ,
1670+ ) ;
1671+
1672+ expectPosition (
1673+ fragmentInstance . compareDocumentPosition ( siblingFollowingRef . current ) ,
1674+ {
1675+ preceding : false ,
1676+ following : true ,
1677+ contains : false ,
1678+ containedBy : false ,
1679+ disconnected : false ,
1680+ implementationSpecific : false ,
1681+ } ,
1682+ ) ;
1683+
1684+ expectPosition (
1685+ emptyFragmentInstance . compareDocumentPosition ( childRef . current ) ,
1686+ {
1687+ preceding : true ,
1688+ following : false ,
1689+ contains : false ,
1690+ containedBy : false ,
1691+ disconnected : false ,
1692+ implementationSpecific : true ,
1693+ } ,
1694+ ) ;
1695+
1696+ expectPosition (
1697+ emptyFragmentInstance . compareDocumentPosition (
1698+ siblingPrecedingRef . current ,
1699+ ) ,
1700+ {
1701+ preceding : true ,
1702+ following : false ,
1703+ contains : false ,
1704+ containedBy : false ,
1705+ disconnected : false ,
1706+ implementationSpecific : true ,
1707+ } ,
1708+ ) ;
1709+
1710+ expectPosition (
1711+ emptyFragmentInstance . compareDocumentPosition (
1712+ siblingFollowingRef . current ,
1713+ ) ,
1714+ {
1715+ preceding : false ,
1716+ following : true ,
1717+ contains : false ,
1718+ containedBy : false ,
1719+ disconnected : false ,
1720+ implementationSpecific : true ,
1721+ } ,
1722+ ) ;
1723+ } ) ;
1724+
16161725 describe ( 'with portals' , ( ) => {
16171726 // @gate enableFragmentRefs
16181727 it ( 'handles portaled elements' , async ( ) => {
0 commit comments