From be7fa407f5b79985db42006c341d888441a91762 Mon Sep 17 00:00:00 2001 From: Adam Azad Date: Wed, 1 Feb 2023 22:47:54 +0000 Subject: [PATCH] fix: csr hydration --- src/api/RestAPI/utils.ts | 2 +- src/components/Container/index.tsx | 1 + src/components/CreateNimi/CreateNimi.tsx | 9 ++- .../NimiPreviewCard/NimiPreviewCard.tsx | 15 +--- src/layout/AppWrapper.tsx | 62 ---------------- src/layout/PageLayout.tsx | 70 +++++++++++++++++++ src/layout/index.ts | 2 +- .../components/RecentPOAPs.tsx | 2 +- .../components/ReorderItem.tsx | 2 +- src/pages/domains/[domain]/index.tsx | 8 ++- src/pages/domains/index.tsx | 5 +- src/types/Theme.ts | 4 +- 12 files changed, 93 insertions(+), 89 deletions(-) delete mode 100644 src/layout/AppWrapper.tsx create mode 100644 src/layout/PageLayout.tsx diff --git a/src/api/RestAPI/utils.ts b/src/api/RestAPI/utils.ts index 9091537d..2743c256 100644 --- a/src/api/RestAPI/utils.ts +++ b/src/api/RestAPI/utils.ts @@ -1,4 +1,4 @@ -import { NimiLinkBaseDetails } from '@nimi.io/card'; +import { NimiLinkBaseDetails } from '@nimi.io/card/types'; import axios from 'axios'; import { CID } from 'multiformats/cid'; diff --git a/src/components/Container/index.tsx b/src/components/Container/index.tsx index cea9f1ad..9a381f17 100644 --- a/src/components/Container/index.tsx +++ b/src/components/Container/index.tsx @@ -7,4 +7,5 @@ export const Container = styled.div` margin-right: auto; max-width: ${MEDIA_WIDTHS.upToMedium}px; width: 100%; + padding: 0 1rem; `; diff --git a/src/components/CreateNimi/CreateNimi.tsx b/src/components/CreateNimi/CreateNimi.tsx index fd5480d1..390b68ad 100644 --- a/src/components/CreateNimi/CreateNimi.tsx +++ b/src/components/CreateNimi/CreateNimi.tsx @@ -5,6 +5,7 @@ import { yupResolver } from '@hookform/resolvers/yup'; import { Nimi, NimiImageType, NimiLinkType, NimiWidget, NimiWidgetType } from '@nimi.io/card/types'; import { nimiValidator } from '@nimi.io/card/validators'; import createDebugger from 'debug'; +import dynamic from 'next/dynamic'; import { KeyboardEventHandler, useState } from 'react'; import { FormProvider, useFieldArray, useForm } from 'react-hook-form'; import { useTranslation } from 'react-i18next'; @@ -34,7 +35,6 @@ import { Card, CardBody } from '../Card'; import { FormGroup, Label, TextArea } from '../form'; import { FormWrapper } from '../form/FormGroup'; import { NimiBlockchainField, ReorderInput } from '../Input'; -import { NimiPreview } from '../NimiPreview'; import { PreviewMobileButton } from '../PreviewMobileButton'; import { ProfileSettings } from '../ProfileSettings'; import { PublishNimiButton } from '../PublishNimiButton'; @@ -42,6 +42,13 @@ import { ReorderGroup } from '../ReorderGroup'; const debug = createDebugger('Nimi:CreateNimi'); +const NimiPreview = dynamic( + async () => { + return import('../NimiPreview').then((mod) => mod.NimiPreview); + }, + { ssr: false } +); + export interface CreateNimiProps { ensAddress: string; ensName: string; diff --git a/src/components/CreateNimi/partials/NimiPreviewCard/NimiPreviewCard.tsx b/src/components/CreateNimi/partials/NimiPreviewCard/NimiPreviewCard.tsx index f1c1575c..c0fc48d9 100644 --- a/src/components/CreateNimi/partials/NimiPreviewCard/NimiPreviewCard.tsx +++ b/src/components/CreateNimi/partials/NimiPreviewCard/NimiPreviewCard.tsx @@ -1,22 +1,11 @@ -import { Nimi } from '@nimi.io/card/types'; +import { Nimi, NimiCard } from '@nimi.io/card'; import { validateNimi } from '@nimi.io/card/validators'; -import dynamic from 'next/dynamic'; import Frame, { FrameContextConsumer } from 'react-frame-component'; import styled, { StyleSheetManager } from 'styled-components'; import { FixedGlobalStyle, ThemeProvider } from '../../../../theme'; import { Card as CardBase } from '../../../Card'; -// document.body is undefined in SSR -const NimiCardApp = dynamic( - async () => { - const NimiCardModule = await import('@nimi.io/card'); - - return NimiCardModule.NimiCard; - }, - { ssr: false } -); - export interface NimiPreviewCardProps { nimi: Nimi; } @@ -65,7 +54,7 @@ export function NimiPreviewCard({ nimi }: NimiPreviewCardProps) { - + diff --git a/src/layout/AppWrapper.tsx b/src/layout/AppWrapper.tsx deleted file mode 100644 index 5af04333..00000000 --- a/src/layout/AppWrapper.tsx +++ /dev/null @@ -1,62 +0,0 @@ -import { PropsWithChildren } from 'react'; -import { useTranslation } from 'react-i18next'; -import styled from 'styled-components'; - -import { Footer } from '../components/Footer'; -import { Header } from '../components/Header'; -import { Heading } from '../components/Heading'; -import { Spinner } from '../components/Spinner'; -import { ENV_SUPPORTED_CHAIN_IDS } from '../constants'; -import { useRainbow } from '../hooks/useRainbow'; -import { useUserInterface } from '../services/useUserInterface'; -import { FOOTER_HEIGHT, HEADER_HEIGHT, MEDIA_WIDTHS } from '../theme'; - -export function PageLayout({ children }: PropsWithChildren) { - const { chainId } = useRainbow(); - const { t } = useTranslation(['common', 'landing']); - const { isSpinnerShown } = useUserInterface(); - - return ( - -
- - {(() => { - if (!ENV_SUPPORTED_CHAIN_IDS.includes(chainId as number)) - return ( - - {t('error.unsupportedNetwork')} - - Please change your network by clicking the account button on the top right. - - - ); - return children; - })()} - - {isSpinnerShown && } -