@@ -723,59 +723,7 @@ describe('suspense hydration', () => {
723723 } ) ;
724724 } ) ;
725725
726- // Currently not supported. Hydration doesn't set attributes... but should it
727- // when coming back from suspense if props were updated?
728- it . skip ( 'should hydrate and update attributes with latest props' , ( ) => {
729- const originalHtml = '<p>Count: 0</p><p data-count="0">Lazy count: 0</p>' ;
730- scratch . innerHTML = originalHtml ;
731- clearLog ( ) ;
732-
733- /** @type {() => void } */
734- let increment ;
735- const [ Lazy , resolve ] = createLazy ( ) ;
736- function App ( ) {
737- const [ count , setCount ] = useState ( 0 ) ;
738- increment = ( ) => setCount ( c => c + 1 ) ;
739-
740- return (
741- < Suspense >
742- < p > Count: { count } </ p >
743- < Lazy count = { count } />
744- </ Suspense >
745- ) ;
746- }
747-
748- hydrate ( < App /> , scratch ) ;
749- rerender ( ) ; // Flush rerender queue to mimic what preact will really do
750- expect ( scratch . innerHTML ) . to . equal ( originalHtml ) ;
751- // Re: DOM OP below - Known issue with hydrating merged text nodes
752- expect ( getLog ( ) ) . to . deep . equal ( [ '<p>Count: .appendChild(#text)' ] ) ;
753- clearLog ( ) ;
754-
755- increment ( ) ;
756- rerender ( ) ;
757-
758- expect ( scratch . innerHTML ) . to . equal (
759- '<p>Count: 1</p><p data-count="0">Lazy count: 0</p>'
760- ) ;
761- expect ( getLog ( ) ) . to . deep . equal ( [ ] ) ;
762- clearLog ( ) ;
763-
764- return resolve ( ( { count } ) => (
765- < p data-count = { count } > Lazy count: { count } </ p >
766- ) ) . then ( ( ) => {
767- rerender ( ) ;
768- expect ( scratch . innerHTML ) . to . equal (
769- '<p>Count: 1</p><p data-count="1">Lazy count: 1</p>'
770- ) ;
771- // Re: DOM OP below - Known issue with hydrating merged text nodes
772- expect ( getLog ( ) ) . to . deep . equal ( [ '<p>Lazy count: .appendChild(#text)' ] ) ;
773- clearLog ( ) ;
774- } ) ;
775- } ) ;
776-
777- // TODO: this should start workign now but still bugged
778- it . skip ( 'should properly hydrate suspense when resolves to a Fragment' , ( ) => {
726+ it ( 'should properly hydrate suspense when resolves to a Fragment' , ( ) => {
779727 const originalHtml = ul ( [
780728 li ( 0 ) ,
781729 li ( 1 ) ,
@@ -848,6 +796,65 @@ describe('suspense hydration', () => {
848796 } ) ;
849797 } ) ;
850798
799+ it ( 'should properly hydrate suspense when resolves to a Fragment without children' , ( ) => {
800+ const originalHtml = ul ( [
801+ li ( 0 ) ,
802+ li ( 1 ) ,
803+ '<!--$s-->' ,
804+ '<!--/$s-->' ,
805+ li ( 2 ) ,
806+ li ( 3 )
807+ ] ) ;
808+
809+ const listeners = [ sinon . spy ( ) , sinon . spy ( ) , sinon . spy ( ) , sinon . spy ( ) ] ;
810+
811+ scratch . innerHTML = originalHtml ;
812+ clearLog ( ) ;
813+
814+ const [ Lazy , resolve ] = createLazy ( ) ;
815+ hydrate (
816+ < List >
817+ < Fragment >
818+ < ListItem onClick = { listeners [ 0 ] } > 0</ ListItem >
819+ < ListItem onClick = { listeners [ 1 ] } > 1</ ListItem >
820+ </ Fragment >
821+ < Suspense >
822+ < Lazy />
823+ </ Suspense >
824+ < Fragment >
825+ < ListItem onClick = { listeners [ 2 ] } > 2</ ListItem >
826+ < ListItem onClick = { listeners [ 3 ] } > 3</ ListItem >
827+ </ Fragment >
828+ </ List > ,
829+ scratch
830+ ) ;
831+ rerender ( ) ; // Flush rerender queue to mimic what preact will really do
832+ expect ( getLog ( ) ) . to . deep . equal ( [ ] ) ;
833+ expect ( scratch . innerHTML ) . to . equal ( originalHtml ) ;
834+ expect ( listeners [ 3 ] ) . not . to . have . been . called ;
835+
836+ clearLog ( ) ;
837+ scratch . querySelector ( 'li:last-child' ) . dispatchEvent ( createEvent ( 'click' ) ) ;
838+ expect ( listeners [ 3 ] ) . to . have . been . calledOnce ;
839+
840+ return resolve ( ( ) => null ) . then ( ( ) => {
841+ rerender ( ) ;
842+ expect ( scratch . innerHTML ) . to . equal ( originalHtml ) ;
843+ expect ( getLog ( ) ) . to . deep . equal ( [ ] ) ;
844+ clearLog ( ) ;
845+
846+ scratch
847+ . querySelector ( 'li:nth-child(2)' )
848+ . dispatchEvent ( createEvent ( 'click' ) ) ;
849+ expect ( listeners [ 1 ] ) . to . have . been . calledOnce ;
850+
851+ scratch
852+ . querySelector ( 'li:last-child' )
853+ . dispatchEvent ( createEvent ( 'click' ) ) ;
854+ expect ( listeners [ 3 ] ) . to . have . been . calledTwice ;
855+ } ) ;
856+ } ) ;
857+
851858 it ( 'Should hydrate a fragment with multiple children correctly' , ( ) => {
852859 scratch . innerHTML = '<!--$s--><div>Hello</div><div>World!</div><!--/$s-->' ;
853860 clearLog ( ) ;
0 commit comments