Skip to content

Commit

Permalink
fix: hydration issue (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioSimou authored Sep 5, 2023
1 parent 05b3178 commit 47e06cf
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 51 deletions.
30 changes: 30 additions & 0 deletions app/features/components/ErrorBoundary/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react'
import { ErrorBoundary } from 'react-error-boundary'

type FallbackRenderProps = {
error: Error
resetErrorBoundary: () => void
}

const FallbackRender = ({ error }: FallbackRenderProps) => {
// eslint-disable-next-line no-console
console.error('Error description: ', error.message)

return (
<div role="alert">
<p className="text-center text-red-500">
We encountered an internal error. Please try again.
</p>
</div>
)
}

type CatchErrorBoundaryProps = {
children: React.ReactNode
}

export const CatchErrorBoundary = ({ children }: CatchErrorBoundaryProps) => {
return (
<ErrorBoundary fallbackRender={FallbackRender}>{children}</ErrorBoundary>
)
}
1 change: 1 addition & 0 deletions app/features/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './Breadcrumbs'
export * from './Page'
export * from './Show'
export * from './Spinner'
export * from './ErrorBoundary'
19 changes: 0 additions & 19 deletions app/pages/Events/components/PastEvents/index.tsx

This file was deleted.

19 changes: 0 additions & 19 deletions app/pages/Events/components/UpcomingEvents/index.tsx

This file was deleted.

45 changes: 34 additions & 11 deletions app/pages/Events/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import {
Page,
Spinner
} from '~/features/components'
import { PastEvents } from './components/PastEvents'
import { UpcomingEvents } from './components/UpcomingEvents'
import { Suspense } from 'react'
import { Section, H2 } from '~/features/components'
import { EventList } from './components/EventList'
import { CatchErrorBoundary } from '~/features/components'

const Events = () => {
const { pastEventsPromise, upcomingEventsPromise } =
const { upcomingEventsPromise, pastEventsPromise } =
useLoaderData() as LoaderData

return (
Expand All @@ -28,14 +29,36 @@ const Events = () => {
</Breadcrumbs>
<H1>Events</H1>
<div className="grid gap-12 lg:gap-24">
<Suspense fallback={<Spinner className="m-auto" />}>
<Await resolve={upcomingEventsPromise}>
<UpcomingEvents />
</Await>
<Await resolve={pastEventsPromise}>
<PastEvents />
</Await>
</Suspense>
<Section data-test-e2e="upcoming-events-section">
<H2>Upcoming events</H2>
<Suspense fallback={<Spinner className="mx-auto" />}>
<CatchErrorBoundary>
<Await resolve={upcomingEventsPromise}>
{(res) => {
if (res.success === false) {
throw new Error(res.message)
}
return <EventList events={res.data} />
}}
</Await>
</CatchErrorBoundary>
</Suspense>
</Section>
<Section data-test-e2e="past-events-section">
<H2>Past events</H2>
<Suspense fallback={<Spinner className="mx-auto" />}>
<CatchErrorBoundary>
<Await resolve={pastEventsPromise}>
{(res) => {
if (res.success === false) {
throw new Error(res.message)
}
return <EventList events={res.data} />
}}
</Await>
</CatchErrorBoundary>
</Suspense>
</Section>
</div>
</Page>
)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"marked": "^4.2.12",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-error-boundary": "^4.0.11",
"react-schemaorg": "^2.0.0",
"remix-image": "^1.4.0",
"schema-dts": "^1.1.2"
Expand Down
21 changes: 19 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 47e06cf

Please sign in to comment.