-
-
Notifications
You must be signed in to change notification settings - Fork 600
fix: crypto.randomUUID causes React-Native build failures
#2858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dplewis
wants to merge
6
commits into
parse-community:alpha
Choose a base branch
from
dplewis:randomuuid
base: alpha
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+23
−24
Open
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a79469c
fix: `crypto.randomUUID` causes React-Native build failures
dplewis 1b8aa51
build types
dplewis 7ba5b9b
Handle error
dplewis fe8a508
improve types
dplewis 6e4fb95
Merge branch 'alpha' into randomuuid
mtrezza 0855c31
Merge branch 'alpha' into randomuuid
mtrezza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,11 @@ | ||
| let uuid: () => string; | ||
|
|
||
| if (process.env.PARSE_BUILD === 'weapp') { | ||
| uuid = function () { | ||
| const s: string[] = []; | ||
| const hexDigits = '0123456789abcdef'; | ||
|
|
||
| for (let i = 0; i < 36; i++) { | ||
| s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1); | ||
| } | ||
|
|
||
| s[14] = '4'; // bits 12-15 of the time_hi_and_version field to 0010 | ||
| s[19] = hexDigits.substr((Number(s[19]) & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01 | ||
| s[8] = s[13] = s[18] = s[23] = '-'; | ||
| return s.join(''); | ||
| }; | ||
| } else if (process.env.PARSE_BUILD === 'browser') { | ||
| // Use native crypto.randomUUID() from the Web Crypto API in browsers | ||
| uuid = () => globalThis.crypto.randomUUID(); | ||
| } else { | ||
| // Use Node.js crypto.randomUUID() for Node and React Native builds | ||
| uuid = require('crypto').randomUUID; | ||
| } | ||
| const uuid = () => { | ||
| if (typeof crypto === 'undefined' || typeof crypto.randomUUID !== 'function') { | ||
| throw new Error( | ||
| 'crypto.randomUUID is not available. ' + | ||
| 'For React Native, import "react-native-random-uuid"' | ||
dplewis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ); | ||
| } | ||
| return crypto.randomUUID(); | ||
dplewis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| export default uuid; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| declare let uuid: () => string; | ||
| declare const uuid: () => `${string}-${string}-${string}-${string}-${string}`; | ||
dplewis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| export default uuid; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.