Skip to content

[expo-modules-core] Ensure uuid.v4 and uuid.v5 imports available on old architecture#33621

Merged
Kudo merged 3 commits into
expo:mainfrom
allboatsrise:fix/expo-modules-core/uuidv4-undefined
Dec 12, 2024
Merged

[expo-modules-core] Ensure uuid.v4 and uuid.v5 imports available on old architecture#33621
Kudo merged 3 commits into
expo:mainfrom
allboatsrise:fix/expo-modules-core/uuidv4-undefined

Conversation

@andrejpavlovic
Copy link
Copy Markdown
Contributor

@andrejpavlovic andrejpavlovic commented Dec 11, 2024

Why

It seems that globalThis?.expo?.uuidv4 is undefined on iOS when this module is loaded. As a result, when trying to call uuid.v4 later in the code, it keeps throwing Native UUID version 4 generator implementation wasn't found in 'expo-modules-core' even though globalThis?.expo?.uuidv4 at that point is available.

I'm assuming in new architecture globalThis?.expo?.uuidv4 is set synchronously, so this would not be an issue. In old architecture however, it would be best to reference this value when executing v4 or v5 calls themselves.

How

Use direct reference to globalThis?.expo?.uuidv4 from inside uuidv4() functions to avoid referencing a stale value.

Test Plan

On iOS the error stops being thrown when calling uuid.v4 within a component.

import { uuid } from 'expo-modules-core'

export const MyComponent = () => {
  useEffect(() => {
    console.log(uuid.v4())
  }, [])
  return null
}

Checklist

  • [*] I added a changelog.md entry and rebuilt the package sources according to this short guide
  • [*] This diff will work correctly for npx expo prebuild & EAS Build (eg: updated a module plugin).
  • [*] Conforms with the Documentation Writing Style Guide

@expo-bot expo-bot added the bot: suggestions ExpoBot has some suggestions label Dec 11, 2024
@andrejpavlovic andrejpavlovic changed the title [expo-modules-core] Ensure uuidv4 and uuidv5 is available on old react native architecture. [expo-modules-core] Ensure uuidv4 and uuidv5 imports available on old architecture Dec 11, 2024
@expo-bot expo-bot added bot: passed checks ExpoBot has nothing to complain about and removed bot: suggestions ExpoBot has some suggestions labels Dec 12, 2024
@andrejpavlovic andrejpavlovic changed the title [expo-modules-core] Ensure uuidv4 and uuidv5 imports available on old architecture [expo-modules-core] Ensure uuid.v4 and uuid.v5 imports available on old architecture Dec 12, 2024
@andrejpavlovic andrejpavlovic marked this pull request as ready for review December 12, 2024 02:52
@github-actions
Copy link
Copy Markdown
Contributor

Subscribed to pull request

File Patterns Mentions
packages/expo-modules-core/** @Kudo, @lukmccall

Generated by CodeMention

Copy link
Copy Markdown
Contributor

@Kudo Kudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi there! thanks for the fix. could you help to run the following command the build js files? that would help to resolve the check-packages ci error

$ cd packages/expo-modules-core
$ yarn prepare

@andrejpavlovic
Copy link
Copy Markdown
Contributor Author

hi there! thanks for the fix. could you help to run the following command the build js files? that would help to resolve the check-packages ci error

@Kudo done!

@andrejpavlovic andrejpavlovic requested a review from Kudo December 12, 2024 15:08
Copy link
Copy Markdown
Contributor

@Kudo Kudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks again for having the fix!

@Kudo Kudo merged commit 5d1c96e into expo:main Dec 12, 2024
@andrejpavlovic andrejpavlovic deleted the fix/expo-modules-core/uuidv4-undefined branch December 12, 2024 17:09
entiendoNull pushed a commit to entiendoNull/expo that referenced this pull request Dec 13, 2024
…on old architecture (expo#33621)

# Why

It seems that `globalThis?.expo?.uuidv4` is undefined on iOS when this
module is loaded. As a result, when trying to call `uuid.v4` later in
the code, it keeps throwing `Native UUID version 4 generator
implementation wasn't found in 'expo-modules-core'` even though
`globalThis?.expo?.uuidv4` at that point is available.

I'm assuming in new architecture `globalThis?.expo?.uuidv4` is set
synchronously, so this would not be an issue. In old architecture
however, it would be best to reference this value when executing `v4` or
`v5` calls themselves.

# How

Use direct reference to `globalThis?.expo?.uuidv4` from inside
`uuidv4()` functions to avoid referencing a stale value.
gaearon added a commit to bluesky-social/social-app that referenced this pull request Dec 16, 2024
gaearon added a commit to bluesky-social/social-app that referenced this pull request Dec 16, 2024
* Fix duplicate expo-modules-core

* Patch expo/expo#33621
tsapeta pushed a commit that referenced this pull request Dec 16, 2024
…on old architecture (#33621)

# Why

It seems that `globalThis?.expo?.uuidv4` is undefined on iOS when this
module is loaded. As a result, when trying to call `uuid.v4` later in
the code, it keeps throwing `Native UUID version 4 generator
implementation wasn't found in 'expo-modules-core'` even though
`globalThis?.expo?.uuidv4` at that point is available.

I'm assuming in new architecture `globalThis?.expo?.uuidv4` is set
synchronously, so this would not be an issue. In old architecture
however, it would be best to reference this value when executing `v4` or
`v5` calls themselves.

# How

Use direct reference to `globalThis?.expo?.uuidv4` from inside
`uuidv4()` functions to avoid referencing a stale value.
@brentvatne brentvatne added the published Changes from the PR have been published to npm label Dec 16, 2024
Signez pushed a commit to Signez/bsky-social-app that referenced this pull request Dec 26, 2024
@Thanaen
Copy link
Copy Markdown
Contributor

Thanaen commented Jan 24, 2025

Hello ! I also have this problem in version 51.0.39. Would it be possible to port this fix to version 51?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot: passed checks ExpoBot has nothing to complain about published Changes from the PR have been published to npm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants