martrapp / astro-vtbot

The 👜 Bag of Tricks ✨ for Astro's View Transitions. ⭐️ Please star to support this work!
https://events-3bg.pages.dev/
ISC License
193 stars 4 forks source link

The connected script is not working correctly (chat) #111

Closed Arhell closed 3 months ago

Arhell commented 3 months ago

Describe the Bug

I use this service, I connected it in astro.config in the head, when it loads everything works correctly, but when I go to the page inside the documentation it stops working.

Please tell me how can I connect it correctly so that it works correctly? maybe inside the plugin? I connected this plugin https://events-3bg.pages.dev/jotter/starlight/inner-workings/integration/#overriding-the-head-component

Thank you for your attention

What's the expected result?

loaded correctly when going to another page

Link to Minimal Reproducible Example

https://github.com/testomatio/docs

Participation

martrapp commented 3 months ago

Hi @Arhell, I had a look at your repository and everything looks great to me!

However, I am not sure whether I have understood the problem correctly. When I click links in the navigation sidebar with the content items, everything seems to work fine. Clicking on the "contact page" link on the "GDPR commitment page" also works fine for me.

when I go to the page inside the documentation it stops working.

Do you mean the links inside the documentation itself do not work?

I noticed that the first two links on the "Start from Scratch" point to https://docs.testomat.io/. When the server runs on a different address, e.g. localhost:4321, those are cross domain links and those will in deed reload instead of doing view transitions.

Could you please provide more detailed step by step example of what does not work for you?

Arhell commented 3 months ago

I mean chat icon Monosnap Testomatio _ Testomatio - Google Chrome 2

https://github.com/testomatio/docs/blob/docs/astro.config.mjs#L38

I'm using an external service. but when I go to another page, for example Start From Scratch No icon Monosnap Start From Scratch _ Testomatio - Google

Arhell commented 3 months ago

I read that you can reinstall the script https://events-3bg.pages.dev/jotter/astro/scripts/

But I’m a little unclear whether I can use the script that I indicated above https://github.com/testomatio/docs/blob/docs/astro.config.mjs#L38

With this component https://github.com/testomatio/docs/blob/docs/src/components/Head.astro

martrapp commented 3 months ago

Thank you! I'll take a look! 👀

martrapp commented 3 months ago

@Arhell, good news: The chat was not lost, it just got invisible ;-) TL;DR: Add this script to your site. A good place would be the Head.astro file.

<script>
  document.addEventListener("astro:before-swap", (e) => {
    const crispStyle = document.querySelector(
      'link[rel="stylesheet"][href*="client.crisp.chat"]'
    );
    if (crispStyle) {
      e.newDocument.head.appendChild(crispStyle.cloneNode(true));
    }
  });
</script>

A bit of background if you are interested:

Hope that helps! Good luck!

Arhell commented 3 months ago

I tested it according to your recommendations.

Everything works perfectly.

Thanks for your work and wonderful plugin.

If possible, add to the documentation that this is possible. (adding chat scripts or another option at your discretion.) with an example, I suggest taking this case

Thanks again

And yes, sorry for the many questions. I just recently started working with this plugin and astro.

And you can correctly rename the name issue, I think I didn’t specify the name correctly.

martrapp commented 3 months ago

You are welcome! Happy if it works for you. Just added to my 'baglog' as you suggested: https://events-3bg.pages.dev/jotter/snippets/things-to-write-about/

martrapp commented 3 months ago

@Arhell, if you find the 👜 Bag of Tricks ✨ helpful, please spread the word and give the repository a star ;-)

Arhell commented 3 months ago

@Arhell, if you find the 👜 Bag of Tricks ✨ helpful, please spread the word and give the repository a star ;-)

Sure, done

Arhell commented 2 months ago

Hi, there is a problem, the chat won't open again( https://docs.testomat.io/ after " Get Started " not work

Arhell commented 2 months ago

@martrapp

martrapp commented 2 months ago

What have you changed?

Arhell commented 2 months ago

What have you changed?

https://github.com/testomatio/docs/blob/docs/src/components/Head.astro

Nothing, I just updated dependencies

Arhell commented 2 months ago

I rolled back the dependencies but it didn't help, I think something new was added in chat plugin

martrapp commented 2 months ago

I'll take a look, but might take a while 👍🏼

martrapp commented 2 months ago

Do i find the failing code in your repository? is it on the main branch or somewhere else?

Arhell commented 2 months ago

Yes, docs(main) branch

martrapp commented 2 months ago

Hi @Arhell, afaict the chat script now comes with two stylysheets that need to be copied over. The original solution above only can cope with one.

Would you please try the following version? It should be able to handle multiple stylesheets.

<script>
  document.addEventListener("astro:before-swap", (e) => {
    document
      .querySelectorAll('link[rel="stylesheet"][href*="client.crisp.chat"]')
      .forEach((el) => {
        e.newDocument.head.appendChild(el.cloneNode(true));
      });
  });
</script>
Arhell commented 2 months ago

Thank you, that's what I assumed when I was looking for the problem, I checked it locally, it works.

Arhell commented 2 months ago

work https://docs.testomat.io/