fix(umami): prevent SSR crash by guarding window access in use()#815
fix(umami): prevent SSR crash by guarding window access in use()#815DrMartinGonzo wants to merge 1 commit into
Conversation
|
@DrMartinGonzo is attempting to deploy a commit to the Nuxt Team on Vercel. A member of the Team first needs to authorize it. |
commit: |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe Umami analytics script integration now guards access to the Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Not very familiar with the codebase, but here goes, it fixed my problems after many hours of not finding useful logs :) This PR fixes a fatal SSR crash (window is not defined) that occurs when using the Umami Analytics script registry in universal rendering mode. Currently, the use() method in packages/script/src/runtime/registry/umami-analytics.ts eagerly attempts to return window.umami without an environment check. If this method is called within a component's setup phase, it crashes the Node.js/Nitro server during the initial render. I simply added an import.meta.client guard to the use() method in the Umami registry. During server-side execution, it now safely bypasses the window access, preventing the crash while preserving the expected behavior on the client.
Not very familiar with the codebase, but here goes, it fixed my problems after many hours of not finding useful logs :)
📚 Description
This PR fixes a fatal SSR crash (window is not defined) that occurs when using the Umami Analytics script registry in universal rendering mode.
Currently, the use() method in packages/script/src/runtime/registry/umami-analytics.ts eagerly attempts to return window.umami without an environment check. If this method is called within a component's setup phase, it crashes the Node.js/Nitro server during the initial render.
I simply added an import.meta.client guard to the use() method in the Umami registry.
During server-side execution, it now safely bypasses the window access, preventing the crash while preserving the expected behavior on the client.