Side effects
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 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!