Amplitude-TypeScript icon indicating copy to clipboard operation
Amplitude-TypeScript copied to clipboard

fix(analytics-browser): prevent error being thrown when server-side rendering

Open johnf opened this issue 10 months ago • 2 comments

Summary

Fixes #710 - I'm not sure why, but this library gets pulled into the SSR part of my next.js project. Likely a treeshaking issue. It then throws and error because navigtator is missing.

Checklist

  • [X] Does your PR title have the correct title format?
  • Does your PR have a breaking change?: No

johnf avatar Apr 18 '24 05:04 johnf

Looks okay to me, hopefully we can merge these changes so it will be helpful to utilize them soon

piyushchauhan2011 avatar Apr 23 '24 10:04 piyushchauhan2011

@izaaz Any chance of getting this merged?

johnf avatar Jun 26 '24 12:06 johnf

@izaaz I've added some extra places where SSR causes issues

johnf avatar Aug 15 '24 00:08 johnf

@johnf - created a new PR for this https://github.com/amplitude/Amplitude-TypeScript/pull/876

For the other two plugin changes, we've already made changes to use getGlobalScope()?.addEventListener instead of window.addEventListener which should have fixed those problems already. Can you please take a look at the other PR and approve it if it looks good?

izaaz avatar Sep 17 '24 04:09 izaaz

Closing in favour of #876

johnf avatar Sep 17 '24 08:09 johnf

@johnf this should be now available in version 2.11.7. Please let me know if you run into issues

izaaz avatar Sep 26 '24 23:09 izaaz