Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comments are being duplicated #352

Open
samueldurantes opened this issue Mar 18, 2025 · 1 comment · May be fixed by #355
Open

Comments are being duplicated #352

samueldurantes opened this issue Mar 18, 2025 · 1 comment · May be fixed by #355

Comments

@samueldurantes
Copy link
Contributor

Currently, when you post a new comment, it being duplicated.

Example:

Screen.Recording.2025-03-18.at.10.24.40.mov
@samueldurantes
Copy link
Contributor Author

Debugging a little, I saw that the comments aren't saved as duplicates in the database, so I figured out that the problem occurs when you add a new comment through the UI.

A comment is added optimistically to the UI state, i.e., before the request is confirmed.

setState((state) => {
const comments = state.get(documentId) ?? []
return state.set(documentId, [...comments, comment])
})
const res = await fetch(
`${NEXT_PUBLIC_API_URL()}/v1/workspaces/${workspaceId}/documents/${documentId}/comments`,
{
credentials: 'include',
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(comment),
}
)
if (!res.ok) {
alert('Failed to create comment')
setState((state) => {
const comments = state.get(documentId) ?? []
return state.set(
documentId,
comments.filter((c) => c.id !== comment.id)
)
})
}
},

Since Briefer is a collaborative platform, the application receives comments made by other users in real time via WebSocket. Knowing this, I was able to discover that after comments are optimistically added, they are added again via WebSocket.

The solution to this problem is very simple; you just have to check if the comment received is already in the UI state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant