Skip to content

Commit

Permalink
fix: summary hydration error
Browse files Browse the repository at this point in the history
  • Loading branch information
Innei committed Aug 27, 2023
1 parent 7a1aaa1 commit 12187b9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
31 changes: 16 additions & 15 deletions src/components/widgets/ai/Summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import { useQuery } from '@tanstack/react-query'
import { useMemo } from 'react'
import type { NoteModel, PageModel, PostModel } from '@mx-space/api-client'
import type { ArticleDataType } from '~/types/api'
import type { FC, ReactNode } from 'react'
import type { FC } from 'react'

import { LogosOpenaiIcon } from '~/components/icons/platform/OpenAIIcon'
import { AutoResizeHeight } from '~/components/widgets/shared/AutoResizeHeight'
import { API_URL } from '~/constants/env'
import { useIsClientTransition } from '~/hooks/common/use-is-client'
import { clsxm } from '~/lib/helper'
import { isNoteModel, isPageModel, isPostModel } from '~/lib/url-builder'

Expand Down Expand Up @@ -64,15 +63,23 @@ export const AISummary: FC<AiSummaryProps> = (props) => {
retryDelay: 5000,
},
)
const isClient = useIsClientTransition()
if (!isClient) return null
// const isClient = useIsClientTransition()
// if (!isClient) return <SummaryContainer isLoading />

const Inner: ReactNode = (
return <SummaryContainer isLoading={isLoading} summary={response?.summary} />
}

const SummaryContainer: Component<{
isLoading: boolean
summary?: string
}> = (props) => {
const { className, isLoading, summary } = props
return (
<div
data-hide-print
className={clsxm(
`space-y-2 rounded-xl border border-slate-200 p-4 dark:border-neutral-800`,
props.className,
className,
)}
>
<div className="flex items-center">
Expand All @@ -81,24 +88,18 @@ export const AISummary: FC<AiSummaryProps> = (props) => {
</div>

<AutoResizeHeight duration={0.3}>
<p className="text-base-content/85 !m-0 text-sm leading-loose">
<div className="text-base-content/85 !m-0 text-sm leading-loose">
{isLoading ? (
<div className="space-y-2">
<span className="block h-5 w-full animate-pulse rounded-xl bg-zinc-200 dark:bg-neutral-800" />
<span className="block h-5 w-full animate-pulse rounded-xl bg-zinc-200 dark:bg-neutral-800" />
<span className="block h-5 w-full animate-pulse rounded-xl bg-zinc-200 dark:bg-neutral-800" />
</div>
) : (
response?.summary
summary
)}
</p>
</div>
</AutoResizeHeight>
</div>
)

return (
<AutoResizeHeight duration={0.2} className="mt-4">
{Inner}
</AutoResizeHeight>
)
}
4 changes: 2 additions & 2 deletions src/components/widgets/xlog/XLogSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const XLogSummary: FC<XLogSummaryProps> = (props) => {
</div>

<AutoResizeHeight duration={0.3}>
<p className="text-base-content/85 !m-0 text-sm leading-loose">
<div className="text-base-content/85 !m-0 text-sm leading-loose">
{isLoading ? (
<div className="space-y-2">
<span className="block h-5 w-full animate-pulse rounded-xl bg-zinc-200 dark:bg-neutral-800" />
Expand All @@ -57,7 +57,7 @@ export const XLogSummary: FC<XLogSummaryProps> = (props) => {
) : (
data?.data
)}
</p>
</div>
{isLoading && (
<p className="border-slate-200 text-right text-sm dark:border-slate-800 ">
(此服务由{' '}
Expand Down

1 comment on commit 12187b9

@vercel
Copy link

@vercel vercel bot commented on 12187b9 Aug 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

shiro – ./

springtide.vercel.app
shiro-git-main-innei.vercel.app
innei.in
shiro-innei.vercel.app

Please sign in to comment.