@@ -25,14 +25,14 @@ import {MissingAttributes} from "./MissingAttributes";
2525import { Inviter } from "./Inviter" ;
2626import { Application } from "./Application" ;
2727import { System } from "./System" ;
28+ import { flushSync } from "react-dom" ;
2829
2930
3031export const App = ( ) => {
3132
3233 const [ loading , setLoading ] = useState ( true ) ;
3334 const navigate = useNavigate ( ) ;
34- const { impersonator, authenticated, reload} = useAppStore ( state => state ) ;
35- const { user} = useAppStore ( state => state ) ;
35+ const { user, impersonator, authenticated, reload} = useAppStore ( state => state ) ;
3636
3737 useEffect ( ( ) => {
3838 setLoading ( true ) ;
@@ -41,47 +41,54 @@ export const App = () => {
4141 configuration ( )
4242 . then ( res => {
4343 useAppStore . setState ( ( ) => ( { config : res } ) ) ;
44+ let route ;
45+
4446 if ( ! res . authenticated ) {
4547 if ( ! res . name ) {
4648 const direction = window . location . pathname + window . location . search ;
4749 localStorage . setItem ( "location" , direction ) ;
48- } else if ( ! isEmpty ( res . missingAttributes ) ) {
49- setLoading ( false ) ;
50- navigate ( "/missingAttributes" ) ;
51- return ;
5250 }
53- const pathname = localStorage . getItem ( "location" ) || window . location . pathname ;
54- const isInvitationAcceptFlow = window . location . pathname . startsWith ( "/invitation/accept" )
55- || pathname . startsWith ( "/invitation/accept" ) ;
56- let route = null ;
57- if ( res . name && ! pathname . startsWith ( "/invitation/accept" ) && ! isInvitationAcceptFlow ) {
58- route = "/deadend"
59- } else if ( pathname === "/" || pathname . startsWith ( "/login" ) || pathname . startsWith ( "/invitation/accept" ) || isInvitationAcceptFlow ) {
60- setLoading ( false ) ;
61- route = isInvitationAcceptFlow ? pathname : window . location . pathname + window . location . search ;
51+ if ( ! isEmpty ( res . missingAttributes ) ) {
52+ route = "/missingAttributes"
6253 } else {
63- //Bookmarked URL's trigger a direct login and skip the landing page
64- login ( res ) ;
54+ const pathname = localStorage . getItem ( "location" ) || window . location . pathname ;
55+ const isInvitationAcceptFlow = window . location . pathname . startsWith ( "/invitation/accept" )
56+ || pathname . startsWith ( "/invitation/accept" ) ;
57+ if ( res . name && ! isInvitationAcceptFlow ) {
58+ route = "/deadend"
59+ } else if ( pathname === "/" || pathname . startsWith ( "/login" ) || pathname . startsWith ( "/invitation/accept" ) || isInvitationAcceptFlow ) {
60+ route = isInvitationAcceptFlow ? pathname : window . location . pathname + window . location . search ;
61+ }
6562 }
6663 if ( ! isEmpty ( route ) ) {
67- setLoading ( false ) ;
68- setTimeout ( ( ) => navigate ( route ) , 50 ) ;
64+ flushSync ( ( ) => {
65+ navigate ( route , { replace : true } )
66+ } ) ;
67+ } else {
68+ //Bookmarked URL's trigger a direct login and skip the landing page
69+ login ( res ) ;
6970 }
71+ setTimeout ( ( ) => setLoading ( false ) , 500 ) ;
7072 } else {
7173 me ( )
7274 . then ( res => {
7375 useAppStore . setState ( ( ) => ( { user : res , authenticated : true } ) ) ;
74- setLoading ( false ) ;
7576 const location = localStorage . getItem ( "location" ) || window . location . pathname + window . location . search ;
7677 const newLocation = location . startsWith ( "/login" ) ? "/home" : location ;
7778 localStorage . removeItem ( "location" ) ;
78- navigate ( newLocation ) ;
79+ debugger ;
80+ flushSync ( ( ) => {
81+ navigate ( newLocation , { replace : true } )
82+ } ) ;
83+ setTimeout ( ( ) => setLoading ( false ) , 500 ) ;
7984 } ) ;
8085 }
8186 } )
8287 . catch ( ( ) => {
83- setLoading ( false ) ;
84- navigate ( "/deadend" ) ;
88+ flushSync ( ( ) => {
89+ navigate ( "/deadend" , { replace : true } )
90+ } ) ;
91+ setTimeout ( ( ) => setLoading ( false ) , 500 ) ;
8592 } )
8693 } )
8794 } , [ reload , impersonator ] ) ; // eslint-disable-line react-hooks/exhaustive-deps
0 commit comments