1- import React , { useState , useMemo } from 'react' ;
1+ import React , { useState , useMemo , useEffect } from 'react' ;
22import PropTypes from 'prop-types' ;
33import { Router } from 'react-router-dom' ;
44
@@ -48,6 +48,7 @@ export default function AppProvider({ store, children }) {
4848 const [ config , setConfig ] = useState ( getConfig ( ) ) ;
4949 const [ authenticatedUser , setAuthenticatedUser ] = useState ( getAuthenticatedUser ( ) ) ;
5050 const [ locale , setLocale ] = useState ( getLocale ( ) ) ;
51+ const [ themeLoaded , setThemeLoaded ] = useState ( false ) ;
5152
5253 useAppEvent ( AUTHENTICATED_USER_CHANGED , ( ) => {
5354 setAuthenticatedUser ( getAuthenticatedUser ( ) ) ;
@@ -61,8 +62,28 @@ export default function AppProvider({ store, children }) {
6162 setLocale ( getLocale ( ) ) ;
6263 } ) ;
6364
65+ useEffect ( ( ) => {
66+ if ( config . THEME_OVERRIDE_URL ) {
67+ const themeLink = document . createElement ( 'link' ) ;
68+ themeLink . href = config . THEME_OVERRIDE_URL ;
69+ themeLink . rel = 'stylesheet' ;
70+ themeLink . type = 'text/css' ;
71+ themeLink . onload = ( ) => setThemeLoaded ( true ) ;
72+ themeLink . onerror = ( ) => setThemeLoaded ( true ) ;
73+
74+ document . head . appendChild ( themeLink ) ;
75+
76+ return ( ) => document . head . removeChild ( themeLink ) ;
77+ }
78+ setThemeLoaded ( true ) ;
79+ } , [ config . THEME_OVERRIDE_URL ] ) ;
80+
6481 const appContextValue = useMemo ( ( ) => ( { authenticatedUser, config, locale } ) , [ authenticatedUser , config , locale ] ) ;
6582
83+ if ( ! themeLoaded ) {
84+ return null ;
85+ }
86+
6687 return (
6788 < IntlProvider locale = { locale } messages = { getMessages ( ) } >
6889 < ErrorBoundary >
@@ -81,8 +102,7 @@ export default function AppProvider({ store, children }) {
81102}
82103
83104AppProvider . propTypes = {
84- // eslint-disable-next-line react/forbid-prop-types
85- store : PropTypes . object ,
105+ store : PropTypes . shape ( { } ) ,
86106 children : PropTypes . node . isRequired ,
87107} ;
88108
0 commit comments