Skip to content

fix(client): polyfill crypto.randomUUID for Twitter/X iOS WebViews - #1426

Merged
kentcdodds merged 3 commits into
mainfrom
cursor/sentry-triage-kody-cloudflare-kody-cloudflare-4p-8d8c
Aug 13, 2026
Merged

kentcdodds merged 3 commits into
mainfrom
cursor/sentry-triage-kody-cloudflare-kody-cloudflare-4p-8d8c

Conversation

@kentcdodds

@kentcdodds kentcdodds commented Aug 13, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes KODY-CLOUDFLARE-4P: Remix @remix-run/ui randomFrameId calls crypto.randomUUID(), which is missing in some in-app browsers (reproduced in Sentry as Twitter 12.15 on iPhone). That aborts client hydration on routes like /community.

Install a getRandomValues-based RFC 4122 v4 polyfill at the top of client/entry.tsx before run() / Sentry init. Leaves an existing randomUUID alone.

Test plan

  • Unit test covers polyfill install, v4 shape, no-op when present, and no-op without getRandomValues
  • npm run typecheck / format:check
  • CI validate after format fix (prior Static fail was indentation; MCP fail was flaky signup email send)
System recap — composes existing primitives (low risk)

Mode: recap · Base: main @ 4d104cb1 · Head: 568d47d5

Classification: composes — adds a client boot shim so Remix's existing crypto.randomUUID() usage works in incomplete WebCrypto environments; no primitive contracts change.

Primitives touched

Primitive Group Impact
app-ui surfaces composes

System map

Client entry polyfills missing crypto.randomUUID before Remix hydration so frame reconcile can run in restricted in-app browsers.

flowchart LR
  entry["client/entry.tsx"] --> polyfill["ensureCryptoRandomUUID"]
  polyfill --> crypto["globalThis.crypto"]
  entry --> remix["remix/ui run()"]
  remix --> frameId["randomFrameId → crypto.randomUUID()"]
  style entry fill:#bbf4bb,stroke:#1a7f37,color:#000
  style polyfill fill:#bbf4bb,stroke:#1a7f37,color:#000
  style crypto fill:#e0e0e0,stroke:#666,color:#000
  style remix fill:#e0e0e0,stroke:#666,color:#000
  style frameId fill:#e0e0e0,stroke:#666,color:#000
Loading

Legend: green = composes (wiring only) · amber = extended by this PR · red = new primitive · gray = context

Risk

Overall low. No auth, isolation, billing, migrations, or DR surface. Isolated client compatibility shim with unit coverage.

Docs

No doc updates required for this compatibility shim.

Open in Web Open in Cursor 

Summary by CodeRabbit

  • Bug Fixes
    • Improved compatibility in environments where crypto.randomUUID() is unavailable.
    • Added secure UUID generation using available cryptographic randomness.
    • Preserved existing implementations and safely handles environments without sufficient crypto support.
    • Ensured UUID generation is available before the application starts.
  • Tests
    • Added coverage for fallback generation, existing implementations, unsupported crypto APIs, and undefined crypto environments.

Remix frame reconcile calls crypto.randomUUID(); Twitter/X iOS WebViews
can omit it and abort hydration (KODY-CLOUDFLARE-4P). Install a
getRandomValues-based v4 polyfill before client boot.

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@coderabbitai

coderabbitai Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a2afa9de-65d2-4940-ae33-8b0a040af6e9

📥 Commits

Reviewing files that changed from the base of the PR and between 48d481f and 568d47d.

📒 Files selected for processing (1)
  • packages/worker/client/ensure-crypto-random-uuid.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/worker/client/ensure-crypto-random-uuid.ts

📝 Walkthrough

Walkthrough

The change adds a guarded crypto.randomUUID polyfill based on getRandomValues, tests its behavior, and runs it during client startup before Sentry initialization and application boot.

Changes

Crypto randomUUID compatibility

Layer / File(s) Summary
Polyfill implementation and validation
packages/worker/client/ensure-crypto-random-uuid.ts, packages/worker/client/ensure-crypto-random-uuid.node.test.ts
The helper generates RFC 4122 v4 UUIDs, preserves existing implementations, handles unsupported crypto objects, and tolerates installation failures. Tests cover these behaviors.
Client startup integration
packages/worker/client/entry.tsx
Client startup invokes ensureCryptoRandomUUID before Sentry initialization and application boot.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Mergeability Score: ⚪ Minimal · up to 568d4

This is a localized client compatibility fix for browsers missing crypto.randomUUID(); no actionable merge-blocking risk remains after normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant ensureCryptoRandomUUID
  participant Crypto
  Client->>ensureCryptoRandomUUID: initialize during startup
  ensureCryptoRandomUUID->>Crypto: check randomUUID and getRandomValues
  ensureCryptoRandomUUID->>Crypto: install UUID v4 fallback when needed
  Client->>Client: initialize Sentry and application
Loading

Possibly related PRs

  • kentcdodds/kody#998: Both changes install a browser API fallback during client startup in packages/worker/client/entry.tsx.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title clearly identifies the client fix and the affected Twitter/X iOS WebViews.
Description check ✅ Passed The description explains the issue, implementation, testing, and risk; the missing explicit Intent heading is non-critical.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/sentry-triage-kody-cloudflare-kody-cloudflare-4p-8d8c

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.

Cast the polyfill UUID string to the DOM lib template-literal return
type so worker typecheck passes.

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@kentcdodds
kentcdodds marked this pull request as ready for review August 13, 2026 14:56
@github-actions

github-actions Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

🔎 Preview deployed: https://kody-pr-1426.kody-a99.workers.dev

Worker: kody-pr-1426
Runtime worker: kody-pr-1426-runtime (https://kody-pr-1426-runtime.kody-a99.workers.dev)
D1: kody-pr-1426-db
KV: kody-pr-1426-oauth-kv

Mocks:

oxfmt check failed on the polyfill helper after the return-type cast edit.

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@kentcdodds
kentcdodds merged commit 25d57a1 into main Aug 13, 2026
10 checks passed
@kentcdodds
kentcdodds deleted the cursor/sentry-triage-kody-cloudflare-kody-cloudflare-4p-8d8c branch August 13, 2026 15:11
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.

2 participants