analytics-next icon indicating copy to clipboard operation
analytics-next copied to clipboard

Side effects

Open gajus opened this issue 3 years ago • 1 comments

I cannot prove this without reading your codebase, but I believe that this application has side-effects that it should not.

For context,

import {AnalyticsBrowser} from '@segment/analytics-next'

breaks our application, and

const AnalyticsBrowser = (await import('@segment/analytics-next')).AnalyticsBrowser;

makes it work.

This is typically indication that simply loading the library is firing some code logic, e.g. registering event handlers.

Such behaviour should not happen until after explicitly invoked by the application.

I have not traced down yet exactly what is breaking, but we are seeing a weird routing behavior that undoes navigation. As mentioned earlier, it only happen when bundling @segment/analytics-next in the critical loading path. If it is loaded after the app has loaded, the app functions as expected.

gajus avatar Jul 26 '22 18:07 gajus

@gajus I agree with you! In the meantime, can you provide version of analytics, your environment (e.g NextJS with node 12), and a stack trace?

thanks!

silesky avatar Jul 26 '22 19:07 silesky