@@ -236,11 +236,17 @@ export default function Home() {
236236 const latestVersion = useRef < string | null > ( null ) ;
237237 const touchStart = useRef < number | null > ( null ) ;
238238 const searchRef = useRef < HTMLInputElement | null > ( null ) ;
239+ const session = useMemo (
240+ ( ) => new URLSearchParams ( window . location . hash . slice ( 1 ) ) ,
241+ [ ] ,
242+ ) ;
243+ const [ access , setAccess ] = useState ( ( ) => session . get ( "access" ) ) ;
239244
240245 const refresh = useCallback ( async ( ) => {
241246 try {
242247 const liveUrl = new URL ( "diff-data.json" , document . baseURI ) ;
243248 liveUrl . searchParams . set ( "t" , String ( Date . now ( ) ) ) ;
249+ if ( access ) liveUrl . searchParams . set ( "access" , access ) ;
244250 const liveResponse = await fetch ( liveUrl , {
245251 cache : "no-store" ,
246252 } ) ;
@@ -268,7 +274,7 @@ export default function Home() {
268274 error instanceof Error ? error . message : "Could not read the snapshot" ,
269275 ) ;
270276 }
271- } , [ ] ) ;
277+ } , [ access ] ) ;
272278
273279 useEffect ( ( ) => {
274280 const initial = window . setTimeout ( ( ) => void refresh ( ) , 0 ) ;
@@ -287,10 +293,9 @@ export default function Home() {
287293 } ;
288294 if ( "EventSource" in window ) {
289295 const eventsUrl = new URL ( "events" , document . baseURI ) ;
290- const project = new URLSearchParams ( window . location . hash . slice ( 1 ) ) . get (
291- "project" ,
292- ) ;
296+ const project = session . get ( "project" ) ;
293297 if ( project ) eventsUrl . searchParams . set ( "project" , project ) ;
298+ if ( access ) eventsUrl . searchParams . set ( "access" , access ) ;
294299 events = new EventSource ( eventsUrl ) ;
295300 events . addEventListener ( "ready" , ( ) => {
296301 stopPolling ( ) ;
@@ -299,6 +304,13 @@ export default function Home() {
299304 void refresh ( ) ;
300305 } ) ;
301306 events . addEventListener ( "update" , ( ) => void refresh ( ) ) ;
307+ events . addEventListener ( "access" , ( event ) => {
308+ const nextAccess = ( event as MessageEvent < string > ) . data ;
309+ if ( ! / ^ [ A - Z a - z 0 - 9 _ - ] { 32 , } $ / . test ( nextAccess ) ) return ;
310+ session . set ( "access" , nextAccess ) ;
311+ window . history . replaceState ( null , "" , `#${ session } ` ) ;
312+ setAccess ( nextAccess ) ;
313+ } ) ;
302314 events . addEventListener ( "error" , startPolling ) ;
303315 } else {
304316 startPolling ( ) ;
@@ -310,7 +322,7 @@ export default function Home() {
310322 events ?. close ( ) ;
311323 window . clearInterval ( ticker ) ;
312324 } ;
313- } , [ refresh ] ) ;
325+ } , [ access , refresh , session ] ) ;
314326
315327 const files = useMemo ( ( ) => snapshot ?. files ?? [ ] , [ snapshot ] ) ;
316328 const currentIndex = Math . max (
0 commit comments