Skip to content

fix: fall back to getRandomValues when crypto.randomUUID is unavailable - #1548

Merged
sorenbs merged 1 commit into
mainfrom
fix/1493-randomuuid-fallback
Jul 18, 2026
Merged

fix: fall back to getRandomValues when crypto.randomUUID is unavailable#1548
sorenbs merged 1 commit into
mainfrom
fix/1493-randomuuid-fallback

Conversation

@sorenbs

@sorenbs sorenbs commented Jul 18, 2026

Copy link
Copy Markdown
Member

Fixes #1493

crypto.randomUUID only exists in secure contexts (https / localhost). When Studio is served over plain HTTP on a LAN host (e.g. http://192.168.x.x:5555), the staged-row draft-id generator crashed the UI with TypeError: crypto.randomUUID is not a function β€” this is also the actually-breaking failure several users hit in the prisma/orm#29731 thread.

Fix

New shared randomUUID() helper (ui/lib/random-uuid.ts) that prefers native crypto.randomUUID and falls back to an RFC 4122 UUIDv4 built from crypto.getRandomValues (available in non-secure contexts), with version/variant bits set explicitly. The single browser-facing call site in ActiveTableView now uses it β€” an exhaustive grep of the browser-bundled entries found no others, and the bundled UUID deps (uuidv7, short-uuid with the custom translator) never call randomUUID.

Verification

  • 3 unit tests: native path preferred; fallback produces valid, unique v4 UUIDs when randomUUID is undefined; version/variant bits verified deterministically.
  • Typecheck/lint clean; changeset included. (The crash can't be reproduced against the localhost demo since browsers treat localhost as secure β€” the tests simulate the non-secure context.)

πŸ€– Generated with Claude Code

crypto.randomUUID only exists in secure contexts (https or localhost).
When Studio is served over plain HTTP on a non-localhost host (e.g.
http://192.168.x.x:5555), staging a new row crashed with
"TypeError: crypto.randomUUID is not a function".

Route UUID generation through a shared helper that prefers the native
crypto.randomUUID and otherwise builds an RFC 4122 UUIDv4 from
crypto.getRandomValues, which is available in non-secure contexts.

Fixes #1493

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 18, 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: ASSERTIVE

Plan: Pro

Run ID: 6a8b7a15-ad7f-4bb9-b8da-e880ebe8ab46

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 81354ff and 379f797.

πŸ“’ Files selected for processing (4)
  • .changeset/plenty-pumas-repeat.md
  • ui/lib/random-uuid.test.ts
  • ui/lib/random-uuid.ts
  • ui/studio/views/table/ActiveTableView.tsx

Summary by CodeRabbit

  • Bug Fixes

    • Fixed Studio startup over plain HTTP on non-localhost hosts where UUID generation was unavailable.
    • Added a compatible fallback for generating UUIDs, preserving staged table row creation across supported browsers and environments.
  • Release

    • Published a patch release for Studio Core.

Walkthrough

Adds a randomUUID utility that uses native crypto.randomUUID when available and otherwise generates UUIDv4 values with crypto.getRandomValues. Tests cover both paths and UUID formatting requirements. Staged table row drafts now use the utility, and a patch changeset documents the HTTP-context fix.

πŸš₯ Pre-merge checks | βœ… 5
βœ… Passed checks (5 passed)
Check name Status Explanation
Title check βœ… Passed The title clearly summarizes the main fix: falling back when crypto.randomUUID is unavailable.
Description check βœ… Passed The description matches the code changes and explains the fallback UUID fix and verification.
Linked Issues check βœ… Passed The PR addresses #1493 by adding a UUIDv4 fallback for non-secure HTTP contexts and updating the call site.
Out of Scope Changes check βœ… Passed The added tests and changeset are directly related to the UUID fallback fix, with no clear unrelated changes.
Docstring Coverage βœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/1493-randomuuid-fallback
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/1493-randomuuid-fallback

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

@github-actions

Copy link
Copy Markdown
Contributor

Compute preview deployed.

Branch: fix/1493-randomuuid-fallback
Service: fix-1493-randomuuid-fallback
Preview: https://jea4hcb1hmjz6zgvafmih2n6.cdg.prisma.build

@sorenbs
sorenbs merged commit f6b4652 into main Jul 18, 2026
3 checks passed
@sorenbs
sorenbs deleted the fix/1493-randomuuid-fallback branch July 18, 2026 13:01
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.

crypto.randomUUID() not available on internal HTTP environment (non-secure context)

1 participant