From 5505bc819afe20a0d103636b3741ec6da0b239a0 Mon Sep 17 00:00:00 2001 From: Martin Portevin Date: Sat, 13 Jun 2026 01:22:13 +0200 Subject: [PATCH] fix(umami): prevent SSR crash by guarding window access in use() 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. --- packages/script/src/runtime/registry/umami-analytics.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/script/src/runtime/registry/umami-analytics.ts b/packages/script/src/runtime/registry/umami-analytics.ts index 6b0ca5438..575a7437a 100644 --- a/packages/script/src/runtime/registry/umami-analytics.ts +++ b/packages/script/src/runtime/registry/umami-analytics.ts @@ -48,7 +48,10 @@ export function useScriptUmamiAnalytics(_options?: schema: import.meta.dev ? UmamiAnalyticsOptions : undefined, scriptOptions: { use() { - return window.umami + if (import.meta.client) { + return window.umami + } + return undefined }, }, }