I’m using Docusaurus along with the @sillsdev/docu-notion plugin to fetch content from Notion pages. Everything runs perfectly when I test it on my local development environment. However, once I deploy the site to production, I encounter a critical error whenever users try to navigate to any page through the sidebar menu.
The error message shows:
ERROR: Maximum call stack size exceeded
RangeError: Maximum call stack size exceeded
The stack trace points to issues with third-party scripts including PostHog analytics and Zaraz tracking services. The error seems to trigger specifically during page navigation in the production environment.
Has anyone experienced similar issues when deploying Docusaurus sites with Notion integration? I’m wondering if this could be related to how the plugin handles data fetching in production versus development mode.
sounds like a race condition between your notion plugin and those tracking scripts. i’ve seen this when analytics code tries to hook into page transitions at the same time docusaurus is processing navigation. try adding a small delay before initializing posthog/zaraz or wrap your notion plugin calls in try-catch blocks. production builds are more agressive with optimizations which might be breaking the timing.
This looks like a bundling optimization issue specific to production builds. I had a similar problem last year where Docusaurus was tree-shaking dependencies differently in production, causing the docu-notion plugin to lose essential references during runtime. The maximum call stack error typically occurs when the plugin tries to fetch Notion data but gets caught in an infinite retry loop due to missing context. Try adding the docu-notion plugin to your webpack externals configuration or check if you need to explicitly include certain dependencies in your production bundle. Another potential fix is adjusting your build command to use development mode bundling temporarily to isolate whether this is purely a production optimization issue.
I encountered something very similar about six months ago when deploying a Docusaurus site with custom plugins. The stack overflow error during navigation often stems from circular dependency issues that only surface in production builds due to different bundling behavior. In my case, the problem was caused by analytics scripts interfering with the router’s navigation lifecycle. I resolved it by deferring the analytics initialization until after the initial page load completed and ensuring all third-party scripts loaded asynchronously. You might want to temporarily disable PostHog and Zaraz to confirm they’re the culprits, then implement proper loading sequences. Also check if your docu-notion plugin is creating any recursive calls during the build process that get amplified by the analytics tracking.