BuildWithMatija
  1. Home
  2. Blog
  3. Next.js
  4. Setting Up Giscus Comments in Next.js (GitHub Discussions)

Setting Up Giscus Comments in Next.js (GitHub Discussions)

Add a zero-database, markdown-ready comment system to your Next.js blog using Giscus and GitHub Discussions, with…

15th October 2026·Updated on:17th November 2026·MŽMatija Žiberna·
Next.js
Setting Up Giscus Comments in Next.js (GitHub Discussions)

⚡ Next.js Implementation Guides

In-depth Next.js guides covering App Router, RSC, ISR, and deployment. Get code examples, optimization checklists, and prompts to accelerate development.

No spam. Unsubscribe anytime.

Related Posts:

  • •Build a Custom Blog Commenting System with Next.js 15 and Sanity CMS
  • •Next.js Markdown Blog: Complete Static Guide for Developers
📄View markdown version
0

Comments

About the author

Matija Žiberna

Matija Žiberna

Full-stack developer, co-founder

AboutResume

Self-taught full-stack developer sharing lessons from building software and startups.

I'm Matija Žiberna, a self-taught full-stack developer and co-founder passionate about building products, writing clean code, and figuring out how to turn ideas into businesses. I write about web development with Next.js, lessons from entrepreneurship, and the journey of learning by doing. My goal is to provide value through code—whether it's through tools, content, or real-world software.

You might be interested in

Build a Custom Blog Commenting System with Next.js 15 and Sanity CMS
Build a Custom Blog Commenting System with Next.js 15 and Sanity CMS

29th July 2025

Next.js Markdown Blog: Complete Static Guide for Developers
Next.js Markdown Blog: Complete Static Guide for Developers

15th March 2026

Contents

  • Introduction
  • Prerequisites
  • Step 1: Enable GitHub Discussions
  • Step 2: Install the Giscus App
  • Step 3: Get Your Giscus Configuration
  • Step 4: Install Giscus in Your Next.js Project
  • Step 5: Create a Comments Component
  • Step 6: Add the Comments Component to Your Pages
  • Step 7: Install next-themes for Dark Mode Support (Optional)
  • Alternative Configuration: Using a Specific Discussion
  • Troubleshooting
  • "giscus is not installed on this repository"
  • "Discussion not found"
  • Repository Visibility Issues
  • Advanced Configuration
  • Custom Styling
  • Lazy Loading
  • Multiple Languages
  • Conclusion
  • Resources
On this page:
  • Introduction
  • Prerequisites
  • Step 1: Enable GitHub Discussions
  • Step 2: Install the Giscus App
  • Step 3: Get Your Giscus Configuration
Build with Matija Logo

Build with Matija

Complex B2B websites, headless CMS platforms, AI workflows, and internal systems designed and built with Next.js and Payload CMS.

Services

  • B2B Website Development
  • CMS Architecture Review & Platform Blueprint
  • Next.js + Payload Advisory
  • AI Integration & Implementation

Resources

  • CMS Hub
  • B2B Website Strategy
  • E-commerce Hub
  • Blog
  • Case Studies
  • About Matija

Payload CMS

  • Payload CMS Developer
  • Payload CMS Migration
  • Payload CMS Demos
  • All Payload CMS Resources

Discuss your project

Planning a rebuild, migration, application, workflow change, or platform decision? Start with the business problem and the system behind it.

Book a discovery callContact me →
© 2026Build with Matija•Alle Rechte vorbehalten•Datenschutzerklärung•Nutzungsbedingungen
BuildWithMatija
Get In Touch

Introduction

In this guide, you will learn how to add a comments system to your Next.js blog or website using Giscus. (If you prefer storing comments directly in your CMS without requiring readers to sign in with GitHub, check out my custom Next.js + Sanity commenting system.) By the end of this tutorial, you'll be able to:

  • Enable GitHub Discussions on your repository
  • Install and configure the Giscus app
  • Implement a comments component in your Next.js application
  • Handle light/dark mode theming
  • Troubleshoot common issues

Giscus is a comments system powered by GitHub Discussions, which means all comments are stored as GitHub Discussion comments. This approach has several advantages:

  • No database required: Comments are stored in GitHub
  • Free hosting: No additional costs for comment storage
  • Markdown support: Full markdown formatting in comments
  • GitHub authentication: Users sign in with their GitHub accounts
  • Moderation tools: Moderate comments directly through GitHub
Diagram

Prerequisites

  • A GitHub repository for your project
  • A Next.js application
  • Basic knowledge of React and TypeScript

Step 1: Enable GitHub Discussions

Before you can use Giscus, you need to enable GitHub Discussions on your repository:

  1. Go to your GitHub repository
  2. Click on the "Settings" tab
  3. Scroll down to the "Features" section
  4. Check the box next to "Discussions"
  5. Click "Set up discussions"
  6. Configure the discussion categories (make sure to have an "Announcements" category)

GitHub Discussions SetupGitHub Discussions Setup

Step 2: Install the Giscus App

Next, you need to install the Giscus app on your repository:

  1. Visit https://github.com/apps/giscus
  2. Click on "Install" or "Configure"
  3. Choose the repository where you want to enable comments
  4. Complete the installation process

Step 3: Get Your Giscus Configuration

After installing the app, you need to get your configuration parameters:

  1. Go to https://giscus.app/
  2. Enter your repository name in the format username/repo
  3. Choose the "Discussion Category" (typically "Announcements")
  4. Choose "Page <-> Discussion Mapping" (typically "pathname")
  5. Enable reactions if desired
  6. Choose the theme that matches your site
  7. Copy the generated configuration

You'll need the following values from the generated script:

  • data-repo
  • data-repo-id
  • data-category
  • data-category-id
  • data-mapping

Step 4: Install Giscus in Your Next.js Project

Install the Giscus React component:

bash
npm install @giscus/react
# or
yarn add @giscus/react

Step 5: Create a Comments Component

Create a new file called Comments.tsx in your components directory:

tsx
'use client'

import React, { useEffect, useState } from 'react'
import Giscus from '@giscus/react'
import { useTheme } from 'next-themes'

interface CommentsProps {
  slug: string
}

export function Comments({ slug }: CommentsProps) {
  const { resolvedTheme } = useTheme()
  const [mounted, setMounted] = useState(false)
  const [theme, setTheme] = useState('light')
  const [error, setError] = useState<string | null>(null)

  // Wait for component to mount to access theme
  useEffect(() => {
    setMounted(true)
    setTheme(resolvedTheme === 'dark' ? 'dark' : 'light')
  }, [resolvedTheme])

  // Handle Giscus errors
  useEffect(() => {
    const handleGiscusError = (event: MessageEvent) => {
      if (
        event.origin === 'https://giscus.app' && 
        event.data.giscus?.error
      ) {
        setError(event.data.giscus.error);
      }
    };

    window.addEventListener('message', handleGiscusError);
    return () => window.removeEventListener('message', handleGiscusError);
  }, []);

  if (!mounted) return null

  return (
    <div className="mt-10 pt-10 border-t border-gray-200 dark:border-gray-800">
      <h2 className="text-2xl font-bold mb-8">Comments</h2>
      
      {error ? (
        <div className="bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-md p-4 mb-6">
          <h3 className="text-red-800 dark:text-red-300 font-medium mb-2">Error loading comments</h3>
          <p className="text-red-700 dark:text-red-400 text-sm">{error}</p>
        </div>
      ) : null}

      <Giscus
        id="comments"
        repo="YOUR_USERNAME/YOUR_REPO"
        repoId="YOUR_REPO_ID"
        category="YOUR_CATEGORY"
        categoryId="YOUR_CATEGORY_ID"
        mapping="pathname"
        term={slug}
        reactionsEnabled="1"
        emitMetadata="1"
        inputPosition="top"
        theme={theme}
        lang="en"
        loading="lazy"
      />
    </div>
  )
}

Replace the placeholder values with your actual configuration from giscus.app.

Step 6: Add the Comments Component to Your Pages

Add the Comments component to your blog post or article page:

tsx
import { Comments } from '@/components/Comments'

export default function BlogPostPage({ params }) {
  const { slug } = params
  
  return (
    <div>
      <h1>My Blog Post</h1>
      <article>
        {/* Your blog post content */}
      </article>
      
      {/* Add the Comments component */}
      <Comments slug={slug} />
    </div>
  )
}

Step 7: Install next-themes for Dark Mode Support (Optional)

If you want to support dark mode, install next-themes:

bash
npm install next-themes
# or
yarn add next-themes

Then wrap your application with the ThemeProvider in your layout:

tsx
// app/layout.tsx
'use client'

import { ThemeProvider } from 'next-themes'

export default function RootLayout({
  children,
}: {
  children: React.ReactNode
}) {
  return (
    <html lang="en" suppressHydrationWarning>
      <body>
        <ThemeProvider attribute="class">
          {children}
        </ThemeProvider>
      </body>
    </html>
  )
}

Alternative Configuration: Using a Specific Discussion

If you want all comments to go to a single discussion instead of creating one per page:

  1. Create a discussion in your GitHub repository
  2. Note the discussion number (e.g., 1 for the first discussion)
  3. Update your Giscus configuration:
tsx
<Giscus
  id="comments"
  repo="YOUR_USERNAME/YOUR_REPO"
  repoId="YOUR_REPO_ID"
  mapping="number"
  term="1" // The discussion number
  reactionsEnabled="1"
  emitMetadata="1"
  inputPosition="top"
  theme={theme}
  lang="en"
  loading="lazy"
/>

Troubleshooting

"giscus is not installed on this repository"

This error occurs when the Giscus app is not installed on your repository. To fix it:

  1. Go to https://github.com/apps/giscus
  2. Click "Install" or "Configure"
  3. Make sure your repository is selected
  4. Complete the installation process

"Discussion not found"

This error occurs when Giscus can't find a matching discussion. This is normal when you first set up Giscus with pathname mapping. To fix it:

  1. Sign in with GitHub in the comments section
  2. Post a comment
  3. Giscus will automatically create the discussion

Repository Visibility Issues

Giscus works best with public repositories. If your repository is private:

  1. Make sure the Giscus app has access to your private repository
  2. Consider using a different comments system for private repositories

Advanced Configuration

Custom Styling

You can customize the appearance of Giscus by wrapping it in a styled container:

tsx
<div className="my-custom-comments-container">
  <Giscus
    // Your configuration
  />
</div>

Lazy Loading

Giscus supports lazy loading to improve page performance:

tsx
<Giscus
  // Your configuration
  loading="lazy"
/>

Multiple Languages

Giscus supports multiple languages:

tsx
<Giscus
  // Your configuration
  lang="en" // Change to your preferred language code
/>

Conclusion

You now have a fully functional comments system powered by GitHub Discussions! Your users can:

  • Sign in with GitHub to leave comments
  • Use Markdown formatting
  • React with emojis
  • Engage in threaded discussions

All comments are stored in GitHub Discussions, making them easy to manage and moderate.

Resources

  • Giscus Official Documentation
  • GitHub Discussions Documentation
  • Next.js Documentation
  • next-themes Documentation

Comments