# Embedded site stuck at "Loading Discussions"

**URL:** <https://meta.discourse.org/t/embedded-site-stuck-at-loading-discussions/341525>\
**Category:** Product Support\
**Tags:** embedding\
**Created:** [December 10, 2024, 6:23am UTC](https://meta.discourse.org/t/embedded-site-stuck-at-loading-discussions/341525 "2024-12-10T06:23:06Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![Graemef](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/graemef/32/498987_2.png) [@Graemef](https://meta.discourse.org/u/Graemef)\
**Post date:** [April 19, 2025, 11:34pm UTC](https://meta.discourse.org/t/embedded-site-stuck-at-loading-discussions/341525/7 "2025-04-19T23:34:56Z")

</div>

Here’s what I have in my next app. It works how I mentioned previously - have to press refresh. Lemme know if it works.

Sometimes i have ot refresh a few times or wait for a while then refresh to get pas tthe ‘loading discussion’ message

```plaintext
<DiscourseComments
          discourseUrl="https://discourseurl.com/"
          discourseEmbedUrl={embedUrl}
          username="system"
        />

```

component:

```plaintext
"use client"

import { useEffect, useRef } from "react"

/**
 * A React component to embed Discourse comments on a website
 *
 * @param {Object} props - Component props
 * @param {string} props.discourseUrl - The URL of your Discourse instance (including trailing slash)
 * @param {string} [props.discourseEmbedUrl] - The URL of the current page (for auto topic creation)
 * @param {number} [props.topicId] - ID of an existing Discourse topic (alternative to discourseEmbedUrl)
 * @param {string} [props.username] - Username for topic creation
 * @param {string} [props.className] - CSS class name to add to the embed
 * @param {string} [props.referrerPolicy] - Referrer policy for the iframe
 */
export default function DiscourseComments({
  discourseUrl,
  discourseEmbedUrl,
  topicId,
  username,
  className,
  referrerPolicy = "no-referrer-when-downgrade",
}) {
  const initialized = useRef(false)

  useEffect(() => {
    // Prevent duplicate initialization
    if (initialized.current) return
    initialized.current = true

    // Validate required props
    if (!discourseUrl) {
      console.error("DiscourseComments: discourseUrl is required")
      return
    }

    if (!discourseEmbedUrl && !topicId) {
      console.error("DiscourseComments: Either discourseEmbedUrl or topicId must be provided")
      return
    }

    // Configure the Discourse embed
    const config = {
      discourseUrl,
      discourseReferrerPolicy: referrerPolicy,
    }

    if (discourseEmbedUrl) {
      config.discourseEmbedUrl = discourseEmbedUrl
    }

    if (topicId) {
      config.topicId = topicId
    }

    if (className) {
      config.className = className
    }

    // Set the global DiscourseEmbed object
    window.DiscourseEmbed = config

    // Load the Discourse embed script
    const script = document.createElement("script")
    script.type = "text/javascript"
    script.async = true
    script.src = `${discourseUrl}javascripts/embed.js`
    document.head.appendChild(script)

    // Cleanup
    return () => {
      document.head.removeChild(script)
      delete window.DiscourseEmbed
    }
  }, [discourseUrl, discourseEmbedUrl, topicId, className, referrerPolicy])

  return (
    <>
      <div id="discourse-comments"></div>
      {username && <meta name="discourse-username" content={username} />}
    </>
  )
}

```

---

_[View the full topic](https://meta.discourse.org/t/embedded-site-stuck-at-loading-discussions/341525)._
