Skip to content

Commit c0ae357

Browse files
authored
fix: always render provider children (#459)
1 parent f9513b0 commit c0ae357

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

dev/devPage.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { createRoot } from 'react-dom/client'
66
import { I18nextProvider, useTranslation } from 'react-i18next'
77
import 'tachyons'
88
import i18n from '../src/i18n.js'
9-
import { ExplorePage, StartExploringPage, IpldExploreForm, IpldCarExploreForm, ExploreProvider, HeliaProvider, useExplore } from '../src/index.js'
9+
import { ExplorePage, StartExploringPage, IpldExploreForm, IpldCarExploreForm, ExploreProvider, HeliaProvider, useExplore, useHelia } from '../src/index.js'
1010

1111
globalThis.Buffer = globalThis.Buffer ?? Buffer
1212

@@ -65,6 +65,12 @@ const HeaderComponent: React.FC = () => {
6565

6666
const PageRenderer = (): React.ReactElement => {
6767
const { setExplorePath, exploreState: { path } } = useExplore()
68+
const { doInitHelia } = useHelia()
69+
70+
useEffect(() => {
71+
void doInitHelia()
72+
// eslint-disable-next-line react-hooks/exhaustive-deps
73+
}, [])
6874

6975
useEffect(() => {
7076
const onHashChange = (): void => {
@@ -87,7 +93,7 @@ const App = (): React.ReactElement => {
8793
<HeliaProvider>
8894
<ExploreProvider>
8995
<HeaderComponent />
90-
<PageRenderer />
96+
<PageRenderer />
9197
</ExploreProvider>
9298
</HeliaProvider>
9399
)

src/components/ExplorePage.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import React from 'react'
22
import { Helmet } from 'react-helmet'
33
import { useTranslation } from 'react-i18next'
44
import ReactJoyride from 'react-joyride'
5+
import { Loader } from '../components/loader/loader.js'
56
import { explorerTour } from '../lib/tours.js'
67
import { useExplore } from '../providers/explore.js'
8+
import { useHelia } from '../providers/helia.js'
79
import CidInfo from './cid-info/CidInfo.js'
810
import ErrorBoundary from './error/ErrorBoundary'
911
import { IpldExploreErrorComponent } from './explore/IpldExploreErrorComponent'
@@ -25,6 +27,7 @@ export const ExplorePage = ({
2527
}): null | React.ReactNode => {
2628
const { t, ready: tReady } = useTranslation('explore')
2729

30+
const { helia } = useHelia()
2831
const { exploreState, doExploreLink } = useExplore()
2932
const { path } = exploreState
3033

@@ -37,8 +40,8 @@ export const ExplorePage = ({
3740
const { error, targetNode, localPath, nodes, pathBoundaries } = exploreState
3841
const sourceNode = nodes?.[0] ?? null
3942

40-
if (!tReady) {
41-
return null
43+
if (!tReady || helia == null) {
44+
return <Loader color='dark' />
4245
}
4346

4447
return (

src/components/loader/loader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react'
22
import styles from './loader.module.css'
33

44
export const Loader: React.FC<{ color?: string }> = ({ color = 'light', ...props }) => {
5-
const className = `dib ${styles.laBallTrianglePath} la-${color} la-sm`
5+
const className = `dib ${styles.laBallTrianglePath} ${color === 'dark' ? styles.laDark : ''} la-sm`
66
return (
77
<div {...props}>
88
<div

src/providers/explore.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { CID } from 'multiformats/cid'
22
import React, { createContext, useContext, useState, useEffect, type ReactNode, useCallback } from 'react'
3-
import { Loader } from '../components/loader/loader.js'
43
import { type LinkObject } from '../components/object-info/links-table'
54
import { ensureLeadingSlash } from '../lib/helpers.js'
65
import { importCar } from '../lib/import-car.js'
@@ -204,12 +203,8 @@ export const ExploreProvider = ({ children, state, explorePathPrefix = '#/explor
204203
}
205204
}, [explorePathPrefix, helia])
206205

207-
if (helia == null) {
208-
return <Loader color='dark' />
209-
}
210-
211206
return (
212-
<ExploreContext.Provider value={{ exploreState, explorePathPrefix, isLoading, doExploreLink, doExploreUserProvidedPath, doUploadUserProvidedCar, setExplorePath }} key={path}>
207+
<ExploreContext.Provider value={{ exploreState, explorePathPrefix, isLoading, doExploreLink, doExploreUserProvidedPath, doUploadUserProvidedCar, setExplorePath }}>
213208
{children}
214209
</ExploreContext.Provider>
215210
)

0 commit comments

Comments
 (0)