99 * Copyright (c) Facebook, Inc. and its affiliates.
1010 */
1111
12+ 'use client' ;
13+
1214import {
1315 createContext ,
1416 memo ,
@@ -89,24 +91,30 @@ function FullBleed({children}) {
8991}
9092
9193function CurrentTime ( ) {
92- const [ date , setDate ] = useState ( new Date ( ) ) ;
93- const currentTime = date . toLocaleTimeString ( [ ] , {
94- hour : 'numeric' ,
95- minute : 'numeric' ,
96- } ) ;
94+ const [ date , setDate ] = useState ( null ) ;
95+
9796 useEffect ( ( ) => {
9897 const msPerMinute = 60 * 1000 ;
99- let nextMinute = Math . floor ( + date / msPerMinute + 1 ) * msPerMinute ;
10098
101- const timeout = setTimeout ( ( ) => {
102- if ( Date . now ( ) > nextMinute ) {
103- setDate ( new Date ( ) ) ;
104- }
105- } , nextMinute - Date . now ( ) ) ;
106- return ( ) => clearTimeout ( timeout ) ;
107- } , [ date ] ) ;
99+ function updateDate ( ) {
100+ setDate ( new Date ( ) ) ;
101+ }
102+
103+ updateDate ( ) ;
104+ const interval = setInterval ( updateDate , msPerMinute ) ;
105+ return ( ) => clearInterval ( interval ) ;
106+ } , [ ] ) ;
108107
109- return < span suppressHydrationWarning > { currentTime } </ span > ;
108+ const currentTime = date ?. toLocaleTimeString ( [ ] , {
109+ hour : 'numeric' ,
110+ minute : 'numeric' ,
111+ } ) ;
112+
113+ return (
114+ < span className = { date === null ? 'invisible' : undefined } >
115+ { currentTime ?? '00:00' }
116+ </ span >
117+ ) ;
110118}
111119
112120const blogSidebar = sidebarBlog . routes [ 1 ] ;
@@ -2367,23 +2375,38 @@ function fetchConf(slug) {
23672375 if ( confCache . has ( slug ) ) {
23682376 return confCache . get ( slug ) ;
23692377 }
2378+ const isInitialConference = slug === 'react-conf-2021' ;
2379+ let initialValue ;
23702380 const promise = new Promise ( ( resolve ) => {
2371- setTimeout ( ( ) => {
2381+ const complete = ( value ) => {
2382+ initialValue = value ;
2383+ resolve ( value ) ;
2384+ } ;
2385+ const load = ( ) => {
23722386 if ( slug === 'react-conf-2021' ) {
2373- resolve ( {
2387+ complete ( {
23742388 id : 0 ,
23752389 cover : reactConf2021Cover ,
23762390 name : 'React Conf 2021' ,
23772391 } ) ;
23782392 } else if ( slug === 'react-conf-2019' ) {
2379- resolve ( {
2393+ complete ( {
23802394 id : 1 ,
23812395 cover : reactConf2019Cover ,
23822396 name : 'React Conf 2019' ,
23832397 } ) ;
23842398 }
2385- } , loadConfDelay ) ;
2399+ } ;
2400+ if ( isInitialConference ) {
2401+ load ( ) ;
2402+ } else {
2403+ setTimeout ( load , loadConfDelay ) ;
2404+ }
23862405 } ) ;
2406+ if ( isInitialConference ) {
2407+ promise . status = 'fulfilled' ;
2408+ promise . value = initialValue ;
2409+ }
23872410 confCache . set ( slug , promise ) ;
23882411 return promise ;
23892412}
@@ -2392,10 +2415,16 @@ function fetchTalks(confId) {
23922415 if ( talksCache . has ( confId ) ) {
23932416 return talksCache . get ( confId ) ;
23942417 }
2418+ const isInitialConference = confId === 0 ;
2419+ let initialValue ;
23952420 const promise = new Promise ( ( resolve ) => {
2396- setTimeout ( ( ) => {
2421+ const complete = ( value ) => {
2422+ initialValue = value ;
2423+ resolve ( value ) ;
2424+ } ;
2425+ const load = ( ) => {
23972426 if ( confId === 0 ) {
2398- resolve ( [
2427+ complete ( [
23992428 {
24002429 id : 'conf-2021-0' ,
24012430 title : 'React 18 Keynote' ,
@@ -2577,7 +2606,7 @@ function fetchTalks(confId) {
25772606 } ,
25782607 ] ) ;
25792608 } else if ( confId === 1 ) {
2580- resolve ( [
2609+ complete ( [
25812610 {
25822611 id : 'conf-2019-0' ,
25832612 title : 'Keynote (Part 1)' ,
@@ -2774,8 +2803,17 @@ function fetchTalks(confId) {
27742803 } ,
27752804 ] ) ;
27762805 }
2777- } , loadTalksDelay ) ;
2806+ } ;
2807+ if ( isInitialConference ) {
2808+ load ( ) ;
2809+ } else {
2810+ setTimeout ( load , loadTalksDelay ) ;
2811+ }
27782812 } ) ;
2813+ if ( isInitialConference ) {
2814+ promise . status = 'fulfilled' ;
2815+ promise . value = initialValue ;
2816+ }
27792817 talksCache . set ( confId , promise ) ;
27802818 return promise ;
27812819}
0 commit comments