Skip to content

fix(deps): make react-native-get-random-values optional - #1310

Merged
abueide merged 1 commit into
masterfrom
abueide/optional-random-values-polyfill
Aug 25, 2026
Merged

fix(deps): make react-native-get-random-values optional#1310
abueide merged 1 commit into
masterfrom
abueide/optional-random-values-polyfill

Conversation

@abueide

@abueide abueide commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Alternative to #1298 (by @SYoder1), same goal: react-native-get-random-values is a hard peer dependency used purely to install a crypto.getRandomValues polyfill, but some apps already polyfill it themselves (e.g. via react-native-quick-crypto) and shouldn't be forced to install a redundant package.

This takes a different implementation approach than #1298:

  • Marks react-native-get-random-values optional in peerDependenciesMeta for both core and sovran (same as fix(deps): switch react-native-get-random-values to optional #1298).
  • Loads it defensively in packages/core/src/uuid.ts using the same try { require(...) } catch {} idiom this codebase already uses for the optional @react-native-async-storage/async-storage peer dependency (packages/sovran/src/persistor/async-storage-persistor.ts), rather than introducing a new local require type declaration.
  • getUUID() now throws a clear, actionable error only if crypto.getRandomValues genuinely isn't available (neither via the polyfill nor any other source) — apps with a working polyfill see no behavior change.

Not a breaking change: apps that already have react-native-get-random-values installed keep working identically (the module still gets required for its side effect); this only removes the forced install for apps using a different polyfill.

Verified locally: yarn lint, yarn format:check (prettier only — shfmt unavailable in my env, but no .sh files are touched), yarn build, yarn typecheck, and yarn test (70/70 suites, 492 passed) all pass with no new warnings introduced.

🤖 Generated with Claude Code

crypto.getRandomValues can already be polyfilled by other packages
(e.g. react-native-quick-crypto), so requiring
react-native-get-random-values unconditionally forces an unnecessary
install on apps that already have a polyfill in place.

Marks it optional in both core and sovran's peerDependenciesMeta, and
loads it defensively at module scope the same way this codebase
already handles the optional async-storage peer dependency
(packages/sovran/src/persistor/async-storage-persistor.ts). getUUID()
now surfaces a clear error only if crypto.getRandomValues genuinely
isn't available.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@abueide
abueide merged commit 849eded into master Aug 25, 2026
11 checks passed
@abueide
abueide deleted the abueide/optional-random-values-polyfill branch August 25, 2026 16:58
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.

1 participant