Skip to content

Commit 0ea0031

Browse files
committed
Fix ssr rendering issues for the show post page.
1 parent 39a8742 commit 0ea0031

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

public/pages/ShowPost/components/CommentInput.tsx

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback, useState } from "react"
1+
import React, { useCallback, useState, useEffect } from "react"
22

33
import { Post, ImageUpload } from "@fider/models"
44
import { Avatar, UserName, Button, Form, MultiImageUploader } from "@fider/components"
@@ -33,6 +33,12 @@ export const CommentInput = (props: CommentInputProps) => {
3333
const [isSignInModalOpen, setIsSignInModalOpen] = useState(false)
3434
const [attachments, setAttachments] = useState<ImageUpload[]>([])
3535
const [error, setError] = useState<Failure | undefined>(undefined)
36+
const [isClient, setIsClient] = useState(false)
37+
38+
// Check if we're running on the client after component mounts
39+
useEffect(() => {
40+
setIsClient(true)
41+
}, [])
3642

3743
const hideModal = () => setIsSignInModalOpen(false)
3844
const clearError = () => setError(undefined)
@@ -76,21 +82,30 @@ export const CommentInput = (props: CommentInputProps) => {
7682
<UserName user={Fider.session.user} />
7783
</div>
7884
)}
79-
<CommentEditor
80-
disabled={!Fider.session.isAuthenticated}
81-
onChange={commentChanged}
82-
onFocus={editorFocused}
83-
initialValue={getContentFromCache()}
84-
placeholder={i18n._("showpost.commentinput.placeholder", { message: "Leave a comment" })}
85-
/>
86-
87-
{hasContent && (
85+
86+
{/* Only render interactive components on the client side */}
87+
{isClient ? (
8888
<>
89-
<MultiImageUploader field="attachments" maxUploads={2} onChange={setAttachments} />
90-
<Button variant="primary" onClick={submit}>
91-
<Trans id="action.submit">Submit</Trans>
92-
</Button>
89+
<CommentEditor
90+
disabled={!Fider.session.isAuthenticated}
91+
onChange={commentChanged}
92+
onFocus={editorFocused}
93+
initialValue={getContentFromCache()}
94+
placeholder={i18n._("showpost.commentinput.placeholder", { message: "Leave a comment" })}
95+
/>
96+
97+
{hasContent && (
98+
<>
99+
<MultiImageUploader field="attachments" maxUploads={2} onChange={setAttachments} />
100+
<Button variant="primary" onClick={submit}>
101+
<Trans id="action.submit">Submit</Trans>
102+
</Button>
103+
</>
104+
)}
93105
</>
106+
) : (
107+
// Simple placeholder for SSR
108+
<div className="comment-input-placeholder p-2">{i18n._("showpost.commentinput.placeholder", { message: "Leave a comment" })}</div>
94109
)}
95110
</Form>
96111
</div>

0 commit comments

Comments
 (0)