Skip to content

GlassToastProvider is not SSR-safe and may cause timeout leaks #2

Description

@gupta-8

Bug

Problem

GlassToastProvider directly uses browser globals:

  • crypto.randomUUID?.()
  • window.setTimeout(...)

It also does not clean up active timeouts if the provider unmounts.

Impact

  • Crashes in SSR or non-browser environments (e.g., Next.js, tests).
  • Possible memory leaks or React warnings due to state updates after unmount.

Location

  • src/components/GlassToast.tsx

Suggested Fix

  • Replace browser-only globals with guarded access:
    • Use globalThis.crypto?.randomUUID?.() with a fallback.
    • Use globalThis.setTimeout or guard against missing window.
  • Track timeout IDs using useRef.
  • Clear all pending timeouts in a cleanup effect on unmount.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions