Skip to content

Commit a326451

Browse files
authored
fix: prevent config UI flash on subdomain first load (#580)
* fix: prevent config UI flash on subdomain first load * remove unintended formatting changes * fixed auto-format lint issues
1 parent 815ea3c commit a326451

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/pages/redirect-page.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,33 @@ const log = uiLogger.forComponent('redirect-page')
1717

1818
const ConfigIframe: React.FC = () => {
1919
const { parentDomain } = getSubdomainParts(window.location.href)
20+
const { isServiceWorkerRegistered } = useContext(ServiceWorkerContext)
21+
2022
let iframeSrc
2123
if (parentDomain == null || parentDomain === window.location.href) {
2224
const url = new URL(window.location.href)
2325
url.pathname = '/'
2426
url.hash = `#/ipfs-sw-config@origin=${encodeURIComponent(window.location.origin)}`
27+
2528
iframeSrc = url.href
2629
} else {
2730
const portString = window.location.port === '' ? '' : `:${window.location.port}`
2831
iframeSrc = `${window.location.protocol}//${parentDomain}${portString}/#/ipfs-sw-config@origin=${encodeURIComponent(window.location.origin)}`
2932
}
3033

34+
const [isVisible, setIsVisible] = useState(false)
35+
36+
useEffect(() => {
37+
// Only show iframe after service worker is registered
38+
if (isServiceWorkerRegistered) {
39+
setIsVisible(true)
40+
}
41+
}, [isServiceWorkerRegistered])
42+
3143
return (
32-
<iframe id="redirect-config-iframe" src={iframeSrc} style={{ width: '100vw', height: '100vh', border: 'none' }} />
44+
<div style={{ display: isVisible ? 'block' : 'none' }}>
45+
<iframe id="redirect-config-iframe" src={iframeSrc} style={{ width: '100vw', height: '100vh', border: 'none' }} />
46+
</div>
3347
)
3448
}
3549

@@ -38,6 +52,7 @@ function RedirectPage ({ showConfigIframe = true }: { showConfigIframe?: boolean
3852
const { isServiceWorkerRegistered } = useContext(ServiceWorkerContext)
3953
const [reloadUrl, setReloadUrl] = useState(translateIpfsRedirectUrl(window.location.href).href)
4054
const [isLoadingContent, setIsLoadingContent] = useState(false)
55+
const [isConfigLoading, setIsConfigLoading] = useState(true)
4156

4257
useEffect(() => {
4358
if (isConfigPage(window.location.hash)) {
@@ -60,6 +75,7 @@ function RedirectPage ({ showConfigIframe = true }: { showConfigIframe?: boolean
6075
if (config != null) {
6176
void doWork(config as ConfigDb)
6277
}
78+
setIsConfigLoading(false)
6379
}
6480
}
6581
window.addEventListener('message', listener)
@@ -90,7 +106,7 @@ function RedirectPage ({ showConfigIframe = true }: { showConfigIframe?: boolean
90106
}
91107
}, [isAutoReloadEnabled, isServiceWorkerRegistered, loadContent])
92108

93-
if (isLoadingContent) {
109+
if (isLoadingContent || isConfigLoading) {
94110
return <LoadingPage />
95111
}
96112

0 commit comments

Comments
 (0)