devrnt / react-use-intercom

☎️ React Intercom integration without the hassle, powered by hooks.
https://devrnt.github.io/react-use-intercom/#/useIntercom
MIT License
328 stars 43 forks source link

initializeDelay also delays entire DOM parsing instead of only the script initializiation #660

Closed omattman closed 7 months ago

omattman commented 7 months ago

Describe the bug Using initializeDelay on IntercomProvider breaks parsed content in nested <Component {...pageProps} /> which means that crawlers can't crawl the correct content.

To Reproduce Steps to reproduce the behavior:

  1. Start new Next.js project using pages router
  2. Wrap Component in _app in the IntercomProvider
  3. Add initializeDelay to the provider with a value of 3000
  4. Add custom title tag to the head tag in index.tsx
  5. Start server
  6. Open terminal and do curl http://localhost:3000
  7. Check for incorrectly parsed title tag
  8. Remove initializeDelay
  9. Check for correctly parsed title tag

Codesandbox link https://codesandbox.io/p/devbox/determined-bell-fmfltc?file=%2Fpages%2F_app.tsx

Expected behavior Only delay the initialization of the Intercom script and not the entire Component DOM

Screenshots WIP will be updated

Desktop (please complete the following information): WIP will be updated

Smartphone (please complete the following information): WIP will be updated

Additional context I think this should be documented in the documentation as an experimental feature as it can have a negative impact in terms of SEO across the entire application. Luckily I caught the issue quickly but I suspect not everyone gives it a second thought.

Plus, thanks for this package!

omattman commented 7 months ago

Update: From the provided sandbox I noticed the curl request only returns wrong results when the next project also includes a _document.tsx file that by default defines shared html accross the application. If used, and there's default SEO put in place inside _app.tsx, then custom SEO on pages will be ignored.

I believe this to be default behaviour and will test it in my own project first before investigating this again.