Skip to content

fix(umami): prevent SSR crash by guarding window access in use()#815

Open
DrMartinGonzo wants to merge 1 commit into
nuxt:mainfrom
DrMartinGonzo:patch-1
Open

fix(umami): prevent SSR crash by guarding window access in use()#815
DrMartinGonzo wants to merge 1 commit into
nuxt:mainfrom
DrMartinGonzo:patch-1

Conversation

@DrMartinGonzo

Copy link
Copy Markdown

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.

@vercel

vercel Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

@DrMartinGonzo is attempting to deploy a commit to the Nuxt Team on Vercel.

A member of the Team first needs to authorize it.

@pkg-pr-new

pkg-pr-new Bot commented Jun 12, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@nuxt/scripts@815

commit: 5505bc8

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e9296995-47bc-47e6-9422-2c5bf2e5f680

📥 Commits

Reviewing files that changed from the base of the PR and between 9d5ccb1 and 5505bc8.

📒 Files selected for processing (1)
  • packages/script/src/runtime/registry/umami-analytics.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/script/src/runtime/registry/umami-analytics.ts

📝 Walkthrough

Walkthrough

The Umami analytics script integration now guards access to the window.umami API behind a client-side environment check. The scriptOptions.use() function conditionally returns window.umami only when running in a browser context (import.meta.client is true) and returns undefined in non-browser environments. This change prevents reference errors when the script executes in server-side rendering or other environments where window is unavailable.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main fix: preventing an SSR crash by guarding window access in the use() method.
Description check ✅ Passed The description is directly related to the changeset, explaining the SSR crash issue and how the import.meta.client guard resolves it.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant