ktquez / vue-disqus

Integrate Disqus count and comments in your application Vue 3, with support for SPA

Home Page:https://ktquez.github.io/vue-disqus/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Same issue as others, unique identifier not working

mjalindahl opened this issue · comments

I have gotten vue-disqus to show up, but each page has different results on whether or not it's going to show old comments or blank comments.

I have tried:
<vue-disqus shortname="name" :identifier="$route.params.id"></vue-disqus>

mounted() {
var vm = this
vm.disqus_id = this.$route.params.id
vm.disqus_url = 'https://website.com/#/gallery/view/'+vm.disqus_id
}
//with
<vue-disqus shortname="name" :identifier="disqus_id" :url="disqus_url"></vue-disqus>

screen shot 2018-08-07 at 8 52 20 pm

Nothing seems to be working. Is this a good way to do it? Basing it off the url? You can see the identifier and url are being set.

Thanks in advance.

@mjalindahl
Thanks for using.

Try only by passing the shortname.
<vue-disqus shortname="my_shortname_disqus" />

I think this is caused by the component not responsive to identifier change...

Hi @ktquez, I tried that, but still same comments on each page.

@alijaya I thought so too, but when you hover over the "Sort By Best" section, you can see the URL is being built from my variables. Is there any other way to be absolutely certain Disqus is getting the right identifier and URL and it's not somehow being replaced later after being mounted() or something? I tried the other recommendation of doing a v-if once the identifier is set, but that didn't seem to work either.

screen shot 2018-08-09 at 2 15 13 am

The t_i in the URL is the identifier, and the t_u is the URL that I'm sending. It seems like it's getting both of these on their end.

Thanks for the help so far.

Even after removing everything except for the shortname, the same comments still load. It's as if Disqus has already made up its mind how to associate the posts with the pages. Absolutely nothing changes if I put in random characters for the identifier and URL.

Maybe this helps?

@mjalindahl
Can you put some preview online?

@mjalindahl : hey... I have found the solution for this... basically, Disqus doesn't support "hash" mode in url like #/, but they support hashbang mode #!/ (which is doesn't exist in Vue 2, there's a workaround about that)

So... the best way is... to make your router.mode in "history", and reset your disqus site (like deleting and make new).

So for detailed problem, maybe it's better if we know how Disqus search link the page with the thread:

  1. First it see if we set the identifier, if it's defined, it will search based on identifier
  2. If it's undefined, it will use url to search, if it's defined, it will search based on url
  3. If it's undefined, it will use window.location as url, and this is where disqus will play some trick, it will ignore all after #, so https://example.com/test will have same url as https://example.com/test#somehash, and because of this if you are in hash mode, https://example.com/ will have same url as https://example.com/#/test. Except if it's hashbang #!, it won't be ignored
  4. If it search with identifier, it will search the thread with suitable identifier, some caveat here, a thread can have multiple identifier. If it finds, it returns the thread
  5. If not, it will search based on the url, url is unique to a thread, if it finds, it returns it.
  6. If not, it will create new thread, and return it.

Example:
You have identifier of foo with url of https://example.com/#/foo.
It searches the database, it doesn't have any entry yet, so it creates new one with:

[
  {
    identifiers: [ 'foo' ],
    url: 'https://example.com'
  }
]

Then you have another page with identifier of baz and url of https://example.com/#/baz.
It searches for baz, not found. Then search the and found https://example.com/ (remember that it ignores the hash?), it returns it. So the database becomes this:

[
  {
    identifiers: [ 'foo', 'baz' ]
    url: 'https://example.com'
  }
]

So the two pages refers to the same thread. Which is annoying.
And if you now want to change it to history mode, so foo page will have url of https://example.com/foo.
But remember that it searches first for foo identifier? And it matches the one and only thread that we have.
The same with the baz.

So you need to clear up all the database first (thus delete and create new), and then don't forget to use history mode.

@alijaya Thank you so much for your input. I'll do that and check in later today. This sounds promising.

@alijaya
Awesome, I had not noticed the hash in the URL, thanks.

@alijaya That did, in fact, work. Great job finding that.

@ktquez you may want to add this to your notes/readme. "Must use History Mode in order for this plugin to work, if you have multiple pages that require Disqus."

Thanks for the help, everyone.

@mjalindahl
I'll add yes, thank you

cool :D... great to hear that :D