The Thread

The <CommentsThread> Component ​

<CommentsThread> is one thread. It renders the same mount point craft.comments.render() writes, with the reserved space, the heading and the count, and the browser package draws the thread inside it once the component has mounted in the browser.

tsx
'use client';

import { CommentsThread } from '@verbb/comments-react';

export function Comments({ entry }) {
    return (
        <CommentsThread
            key={entry.uri}
            ownerUri={entry.uri}
            sort="top"
            loadMode="button"
            onCommentCreated={(event) => track('Comment posted', event.detail.moderationState)}
        />
    );
}

Props ​

PropWhat it does
ownerId or ownerUriThe element the comments belong to, by its ID or its URI.
siteIdThe site, for a multi-site install. Defaults to the provider's.
endpointThe data API's address. Defaults to the provider's, then /actions/comments/api on the page's own origin.
loadModevisible, the default, loads the thread just before it scrolls into view, button waits for Show comments, and eager loads it straight away, as below.
sortnewest, oldest or top.
limitTop-level comments in each page, from 1 to 50.
themelight, dark, auto or none. Defaults to the provider's, then light, as Dark Mode explains.
darkSelectorA selector, such as html.dark, that switches the thread to dark while it matches <html>.
themeConfigClasses and attributes for the ten controls, merged control by control over the provider's, as Styling explains.
parts and fieldsPart and field overrides, as Part Overrides and Field Overrides explain.
labelsWording to use instead of the site's translations, as below.
countThe comment count to show before the thread's data arrives, such as from fetchCommentsCount().
idThe mount point's id. Defaults to comments-<ownerId>-<siteId>, as render() writes it.
classNameClasses for the mount point, alongside comments.
onMounted, onCommentCreated and the restA prop for every event, as Events and Validation lists.

When Props Change ​

Give the component a key of the owner, as above, so moving to another post starts a fresh thread rather than reusing the old one. It also starts a new thread by itself when ownerId, ownerUri, siteId, endpoint or limit changes. A new sort re-sorts a loaded thread in place, keeping a half-written comment and the reader's place, and starts a thread that's still waiting again in the new order, as it does a thread whose sort is taken away, which goes back to the site's default. A new theme switches the drawn thread in place, and new themeConfig, parts, fields or labels redraw it. loadMode and count are read when the thread starts.

Props that are objects, such as themeConfig and parts, are compared by what they hold, so writing them inline doesn't redraw the thread on every render. Components given as overrides are the exception, as Part Overrides with Components explains.

The Provider ​

<CommentsProvider> gives every thread and hook inside it the same settings, and a thread's own props win. themeConfig merges control by control, so the provider can put your design system's classes on every button while one thread adds a title to its own. Providers can be nested, each adding to the one around it.

SettingWhat it does
endpointThe data API's address, such as https://cms.example.com/actions/comments/api.
authHow the person is identified, below.
siteIdThe site, for a multi-site install.
themeConfig, parts, fields and labelsThe same as the props, for every thread.
theme and darkSelectorThe same as the props, for every thread.
loadEditorLoads Editor for rich comments. Defaults to import('@verbb/editor'), which your bundler keeps in a file of its own.
nonceA Content Security Policy nonce for the scripts and stylesheets a thread loads, such as the spam protection's challenges.
fetchA fetch to use instead of the global one.

Signing In ​

auth chooses how the person is identified, and depends on where your app runs relative to Craft. Each way comes from @verbb/comments-core, and Signing In explains them in full.

  • On Craft's own domain, or behind a proxy that forwards /actions/comments/* to Craft, leave auth out. Craft's session cookie identifies the person.
  • On another subdomain of the same site, use cookieSession({ profile: 'same-site-credentialed' }). Craft's defaultCookieDomain must be the parent domain, and the app's origin must be listed under Settings → Other Sites with Shared Cookies on.
  • On a different site, use memberToken() for signed-in members and guestSession() for guests, with the app's origin listed under Settings → Other Sites, and Member Tokens on for members.
tsx
'use client';

import { guestSession, memberToken } from '@verbb/comments-core';
import { CommentsProvider } from '@verbb/comments-react';
import { useMemo, type ReactNode } from 'react';

export function CommentsSettings({ signedIn, children }: { signedIn: boolean; children: ReactNode }) {
    // One provider for each kind of sign-in, so signing in or out starts the threads again as that person.
    const auth = useMemo(() => signedIn
        ? memberToken({ getToken: () => fetch('/api/comments-token', { cache: 'no-store' }).then((response) => response.json()) })
        : guestSession({ storage: sessionStorage }), [signedIn]);

    return <CommentsProvider endpoint="https://cms.example.com/actions/comments/api" auth={auth}>{children}</CommentsProvider>;
}

Make the provider once, outside your component or with useMemo(), as above. Each provider keeps its own token, so one made afresh on every render fetches a new member token for its first request, and a guestSession() without storage starts a new guest session each time, losing the guest's pending comment. A new provider of the same kind is taken over without starting the thread again, so nobody loses the comment they're writing, while a different kind, such as a guest signing in as a member, starts the thread again. On sign-out, call reset() on the provider you gave last, and every thread and hook using it clears what was private and reads the viewer again.

When the Thread Loads ​

Most visitors to a post never scroll down to its comments, so a thread waits until it's needed before it loads anything. Until then the page has only the mount point, with the heading, the comment count and the space the thread will fill.

loadModeWhen the thread loads
visibleJust before it scrolls into view, about 600 pixels ahead. This is the default.
buttonWhen the visitor presses Show comments (42), which is drawn in the thread's place.
eagerAs soon as the script starts.

A link to a comment, such as #comment-1446, ?comment=1446 or a comment's UID after #comment-, loads the thread straight away whatever its mode, and scrolls to the comment. So does following such a link within the page, while other in-page links, such as a table of contents, leave a waiting thread waiting.

loadMode is read when the thread starts. To load a button thread from a control of your own, such as a drawer's toggle, keep its controller from onMounted and call load(), which does nothing to a thread that has loaded.

tsx
const [controller, setController] = useState<CommentsController>();

<button type="button" onClick={() => { setOpen(true); controller?.load(); }}>Comments</button>
<CommentsThread ownerUri={uri} loadMode="button" onMounted={(event) => setController(event.detail.controller)} />

The script a page downloads first is small. It finds the threads, draws their waiting state, and imports the renderer when a thread is about to be needed. The comment forms are a separate piece again, imported when someone heads for one, or straight away for a signed-in member, whose form shows at the top of the thread. A bundler that splits code at dynamic import() calls keeps these pieces apart, as Vite and webpack do, and the plugin's own script is built the same way.

If a piece can't load, the thread says so where it would have been, with Try again. That can happen to a tab left open while the plugin is updated, because the pieces have new names, and Try again or reloading the page fixes it. Chrome and other Chromium browsers never fetch a failed piece again on the same page, so there Try again for the thread or the comment form reloads the page once the server answers, and a thread that waited for Show comments then shows straight away. The file tray's Try again loads it again without a reload, so a comment being written stays.

While a thread loads, its waiting state stays exactly where it is, with aria-busy="true" on the loading line, and the heading's count is updated from the response in case a cached page held an old number. A long thread draws its first 45 comments at once and the rest in batches while the browser is idle. A link to a comment, focus moving to one and Load more draw what they need straight away.

Labels ​

Every word the thread shows comes from the site's translations in Craft's comments category, so changing wording per site and language is usually done with a static translation file, as the plugin's Text & Translations explains. labels is for wording that belongs to your JavaScript rather than your Craft site, such as an app on another domain that wants its own tone. It takes the keys below, and wins over the site's translations.

tsx
<CommentsProvider endpoint="https://cms.example.com/actions/comments/api" labels={{ post: 'Send', editorPlaceholder: 'What do you think?' }}>
    {children}
</CommentsProvider>

A thread's own labels merge over the provider's, key by key.

Every label, with its default

Placeholders such as {count} and {name} are filled in by the renderer, so keep them in your wording. A label set to an empty string is ignored, and the site's own wording is used instead.

The keys marked “No” in the last column aren't in Craft's translation list. The renderer uses its own English for them unless you give labels.

KeyDefault textTranslated through Craft
commentCountOne1 commentYes
commentCountOther{count} commentsYes
showCommentsShow commentsYes
showCommentsCountShow comments ({count})Yes
loadingLoading comments…Yes
loadMoreLoad more commentsYes
emptyNo comments yet.Yes
beFirstBe the first to comment.Yes
closedComments are closed.Yes
sortLabelSort commentsYes
sortNewestNewestYes
sortOldestOldestYes
sortTopTopYes
replyReplyYes
replyToReply to {name}…Yes
replyingToReplying toYes
cancelReplyCancel replyYes
cancelCancelYes
postPostYes
postingPosting…Yes
saveSave commentYes
editEditYes
editedEditedYes
deleteDeleteYes
deleteConfirmDelete this comment? This can’t be undone.Yes
likeLikeYes
likesLikesYes
upvoteUpvoteYes
downvoteDownvoteYes
scoreScoreYes
reportReport…Yes
reportTitleReport this commentYes
reportReasonWhat’s wrong with it?Yes
reportDetailsAnything else?Yes
reportDetailsHintOptional. Only moderators see this.Yes
sendReportSend reportYes
reportSentThanks for reporting this. A moderator will take a look.Yes
reportWithdrawnReport withdrawn.Yes
closeCloseYes
moreActionsMore actionsYes
copyLinkCopy linkYes
linkCopiedLink copied.Yes
showRepliesShow repliesYes
hideRepliesHide repliesYes
loadMoreRepliesLoad more repliesYes
guestGuestYes
commentByComment byYes
unavailableComment unavailable.Yes
awaitingApprovalWaiting for approval. Only you can see this until a moderator approves it.Yes
editorPlaceholderAdd to the conversation…Yes
editPlaceholderEdit your comment…Yes
yourCommentYour commentYes
writeSomethingFirstWrite something first.Yes
tooLongToo long by {count} charactersYes
charactersLeft{count} characters leftYes
characterCount{count} of {limit} charactersYes
draftSavedDraft savedYes
draftRestoredRestored your draft from {time}.Yes
discardConfirmDiscard what you’ve written?Yes
discardDiscardYes
uploadInProgressPlease wait for your upload to finish.Yes
joinTitleJoin the conversationYes
signInSign inYes
signInToCommentSign in to comment.Yes
signInOrGuestSign in to comment and hear about replies, or post as a guest.Yes
commentAsGuestComment as a guestYes
postingAsPosting asYes
yourDetailsYour detailsYes
yourNameYour nameYes
yourEmailYour emailYes
notShownPubliclyNot shown publiclyYes
replyEmailsEmail me when someone replies. We’ll ask you to confirm your address first.Yes
followFollowYes
followingFollowingYes
followByEmailFollow by emailYes
errorSomething went wrong. Please try again.Yes
tryAgainTry againYes
moderatorModeratorYes
moderatorViewModerator view.Yes
reviewInCommentsReview in CommentsYes
heldCount{count} heldYes
reportedCount{count} reportedYes
showHeldShow heldYes
hideHeldHide heldYes
approveApproveYes
markSpamMark as spamYes
notSpamNot spamYes
removeRemoveYes
restoreRestoreYes
keepKeepYes
spamSpamYes
gifGIFYes
gifAddAdd a GIFYes
gifSearchSearch GIPHYYes
gifResultsGIFsYes
gifRemoveRemove GIFYes
gifEmptyNo GIFs found.Yes
gifPoweredByPowered by GIPHYYes
gifUnavailableGIFs can’t be loaded right now.Yes
foldedReportsComment marked as inappropriateYes
foldedDownvotesComment hidden due to low ratingYes
showFoldedShow commentYes
authorScoreTotal votes across this user’s commentsYes
commentsCommentsYes
moderationModerationYes
onThisPageon this pageYes
holdHoldYes
removedNoteRemoved · only moderators see thisYes
chooseOptionChoose…Yes
addFilesAdd filesYes
addFileAdd a fileYes
removeFileRemoveYes
retryUploadTry {name} againYes
uploadingUploading…Yes
uploaded{name} uploaded.Yes
uploadFailed{name} didn’t upload.Yes
fileRemoved{name} removed.Yes
uploadLimitsUp to {count} files, {size} each.Yes
uploadLimitUp to {size}.Yes
fileTypeNotAllowed{name} can’t be added here. Choose {types}.Yes
fileTooLarge{name} is larger than {size}.Yes
tooManyFilesYou can add up to {count} files here.Yes
formFailedThe comment form couldn’t load. Please try again.No, labels only
uploadsFailedRemove or try again the files that didn’t upload, so nothing is left out.No, labels only
uploadsUnavailableFiles can’t be added right now.No, labels only

Events ​

Every event a thread dispatches is a prop, named after the event, such as onCommentCreated for comments:comment-created. Events and Validation lists them all with what each one gives, and covers checking a comment before it's posted.

Server Rendering ​

On the server, <CommentsThread> renders only its mount point, so there's nothing inside it for hydration to disagree with, and the thread loads in the browser. The package's main entry is a client module, marked 'use client', so a server component can render <CommentsThread> directly as long as it passes no functions. Event props and component overrides are functions, so put a thread that has them in a file of your own that starts with 'use client', as Next.js shows.

Last updated: Nov 18, 2026, 12:27 PM