Embedded topic comments are missing if containing page's URL includes a fragment identifier

AI-generated summary

A user, aribadernatal, encountered an issue with Discourse’s comment embedding feature. The feature doesn’t work when the external site’s URL includes a fragment identifier (e.g., http://example.com/test.html#references). This is due to the companion pairing being based on an exact string match. The user suggests that the match should be less strict.

vinothkannans proposed a solution by modifying the discourseEmbedUrl in the embed code to remove the query string from the URL. aribadernatal found this solution helpful and is willing to create a pull request (PR) to implement it.

Discourse’s ability to embed comments from a topic into an external site is wonderful and works amazingly well.

I did run into a small issue that I would consider a bug:

If I have a page on an external site http://example.com/test.html, all comments from the companion topic are displayed in the iframe, as expected. If I visit the same page with a fragment identifier appended to the URL (e.g. http://example.com/test.html#references or even http://example.com/test.html#), the comments do not display. It seems like this is because the companion pairing is based on an exact string match. In practice, I think an exact string match is too strict.

I would expect the following external site URLs to all embed the same set of comments:

  1. http://example.com/test.html
  2. http://example.com/test.html#
  3. http://example.com/test.html#foo
1 Like

The above solution may help you. It will remove query strings too. So you have to remove the ? character. Anyway I will check your suggestion. If you can create a PR that will be more helpful.

2 Likes

Modifying the discourseEmbedUrl in the embed code sounds like a simple solution here. Thanks!