Skip to content

fix: SSR-compatible random ID generation (avoid window.crypto) - #20

Merged
RA9 merged 2 commits into
masterfrom
copilot/avoid-window-crypto-usage
Jul 18, 2026
Merged

fix: SSR-compatible random ID generation (avoid window.crypto)#20
RA9 merged 2 commits into
masterfrom
copilot/avoid-window-crypto-usage

Conversation

Copilot AI commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

EzyTables constructor used window.crypto.getRandomValues(...) to generate dynamic CSS class suffixes, causing ReferenceError: window is not defined in Node.js/SSR environments (Next.js, Nuxt, etc.).

Change

  • src/index.ts: Replace window.crypto with globalThis.crypto (optional-chained) and fall back to Math.random() when the Web Crypto API is unavailable.
// Before
const randomId = window.crypto.getRandomValues(new Uint32Array(1))[0];

// After
const randomId =
  globalThis.crypto?.getRandomValues(new Uint32Array(1))?.[0] ??
  Math.floor(Math.random() * 0xffffffff);

globalThis.crypto is available natively in browsers and Node ≥ 19; the Math.random() fallback covers older runtimes that lack the Web Crypto API.

Copilot AI changed the title [WIP] Fix window.crypto usage for SSR compatibility fix: SSR-compatible random ID generation (avoid window.crypto) Jul 18, 2026
Copilot AI requested a review from RA9 July 18, 2026 11:18
Copilot finished work on behalf of RA9 July 18, 2026 11:18
@RA9
RA9 marked this pull request as ready for review July 18, 2026 13:15
@RA9
RA9 merged commit 0a5a7a9 into master Jul 18, 2026
4 checks passed
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.

Avoid window.crypto usage in constructor for SSR compatibility

2 participants