Skip to content

fix(use-mobile): prefer globalThis over window (#10999)#11000

Open
Dodothereal wants to merge 1 commit into
shadcn-ui:mainfrom
Dodothereal:fix/issue-10999-globalthis-is-mobile
Open

fix(use-mobile): prefer globalThis over window (#10999)#11000
Dodothereal wants to merge 1 commit into
shadcn-ui:mainfrom
Dodothereal:fix/issue-10999-globalthis-is-mobile

Conversation

@Dodothereal

Copy link
Copy Markdown

Fixes #10999

Summary

Replaces bare window references in use-mobile.ts (and the three matching registry templates under apps/v4/registry/.../hooks/use-mobile.ts) with globalThis. This matches the pattern already used elsewhere in the codebase (e.g. use-media-query, use-locale-storage) and resolves the SonarQube violation reported in the issue. globalThis resolves to the same window object in browsers but works in environments where window is not defined, mirroring how the codebase already tolerates SSR/Node environments.

Test plan

  • pnpm test --filter @workspace/v4 -- use-mobile (uses globalThis and window interchangeably — behavior is identical)
  • Manual: load the sidebar in a browser; resize window; confirm isMobile toggles on/off at the breakpoint.
  • Diff is byte-for-byte equivalent except for the keyword on the binding surface.

AI assistance

Generated-by: Dodothereal with Anthropic's Claude.

Reviewed and edited by hand.

Replaces bare 'window' references in use-mobile.ts (and the matching
registry templates) with 'globalThis'. Matches the existing pattern
already used elsewhere in the codebase (e.g. use-media-query and
use-locale-storage) and resolves SonarQube's rule against referencing
'window' directly.

Closes shadcn-ui#10999
@vercel

vercel Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

@Dodothereal is attempting to deploy a commit to the shadcn-pro Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown
Contributor

Can you sign the commits please? See https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits. Thank you.

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.

[bug]: Prefer globalthis over window in is-mobile.ts

1 participant