polite-fountain-16043
10/09/2023, 10:21 PMNext.js 13 (with App Router)...
We currently load Rudderstack via npm (v2), and due to some Server-Side-Rendering (SSR) quirks, we continuously ran into a window is not defined error on the server. This doesn't prevent Rudderstack from loading properly, but has created an obscene amount of noise in our logs and reduced the effectiveness of some of our functional/e2e tests.
In searching for a solution, I discovered the V3 release, and was pleased to see that things have improved and that there is even mention of Next.js in the docs--however, it only mentions it for the npm integration path.
So my questions are:
• When importing from @rudderstack/analytics-js/bundled as the docs recommend for Next.js, we lose our type definitions "Cannot find module '@rudderstack/analytics-js/bundled' or its corresponding type declarations"--how can we fix this?
• Is the npm integration the recommended path for Next.js's new App Router, or could the CDN snippet also work?
• We only create new RudderAnalytics instances and call load() from inside of useEffect() hooks, so we're confused why we're getting window is not defined on the server unless the Rudderstack npm package does some self-initialization immediately upon import, causing some of its code to be ran when Next.js makes an initial render of client-side components on its server before hydrating on the client. Can you provide any insight to this behavior?millions-activity-52391
10/09/2023, 10:21 PMpolite-fountain-16043
10/09/2023, 10:58 PMv3 via npm in Next.js, I'm seeing lots of Hydration mismatch errors in the browser:
react-dom.development.js:6824 Uncaught Error: Hydration failed because the initial UI does not match what was rendered on the server.
at throwOnHydrationMismatch (webpack-internal:///(:3000/app-pages-browsemillions-activity-52391
10/10/2023, 1:24 PMimport { RudderAnalytics } from '@rudderstack/analytics-js/bundled';
However, the device mode integrations do not still throw some errors with the v3 SDK.polite-fountain-16043
10/11/2023, 6:40 PMpolite-fountain-16043
10/11/2023, 6:41 PMpolite-fountain-16043
10/11/2023, 8:40 PMmillions-activity-52391
10/12/2023, 8:30 AMpolite-fountain-16043
10/12/2023, 5:06 PMpolite-fountain-16043
10/12/2023, 5:25 PMrudderanalytics.page() from within a useEffect of a client component for each page.polite-fountain-16043
10/12/2023, 6:26 PMpolite-fountain-16043
10/12/2023, 6:45 PMmillions-activity-52391
10/13/2023, 10:45 AMmillions-activity-52391
10/17/2023, 2:58 PMmillions-activity-52391
10/20/2023, 2:35 PM