fix(expo): Fix expo-auth-session import leak and env var detection#8607
Draft
chriscanin wants to merge 1 commit into
Draft
fix(expo): Fix expo-auth-session import leak and env var detection#8607chriscanin wants to merge 1 commit into
chriscanin wants to merge 1 commit into
Conversation
`ClerkProvider` previously called `require('expo-web-browser')` synchronously
inside an `isWeb()` runtime gate. Metro's static analyzer resolves literal-string
`require()` calls regardless of runtime gates or try/catch, so production
bundling failed for native consumers who don't install `expo-web-browser` (an
optional peer dependency).
Splits the web-only `maybeCompleteAuthSession()` call into a platform-specific
helper. Metro/Expo's platform resolver picks `maybeCompleteAuthSession.web.ts`
for web bundles and the no-op `maybeCompleteAuthSession.ts` for native — so
native dist no longer references `expo-web-browser`.
Behavior is unchanged at runtime on both platforms; the fix is purely at bundle
time.
The "env var detection" half of MOBILE-402 was already resolved in #7655
(publishableKey made a required prop, env-var fallback removed). No further
change needed there.
MOBILE-402
🦋 Changeset detectedLatest commit: fa2e094 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
ClerkProviderpreviously calledrequire('expo-web-browser')synchronously inside anisWeb()runtime gate. Metro's static analyzer resolves literal-stringrequire()calls regardless of runtime gates or try/catch, so production bundling failed for native consumers who don't installexpo-web-browser(an optional peer dependency).Reported by Sam Aubin on Plain (per the MOBILE-401/402 attachment thread). MOBILE-401 covered the React peer-dep angle; MOBILE-402 covers the bundle-time crash.
What changed
packages/expo/src/provider/maybeCompleteAuthSession.ts— native no-oppackages/expo/src/provider/maybeCompleteAuthSession.web.ts— moves therequire('expo-web-browser')+WebBrowser.maybeCompleteAuthSession()call into a web-only filepackages/expo/src/provider/ClerkProvider.tsxnow imports and calls the helper instead of inlining therequire()@clerk/clerk-expoonlyMetro / Expo's platform resolver picks the
.web.tsfile for web bundles and the base.ts(no-op) for native. Native dist no longer referencesexpo-web-browser.Behavior at runtime
isWeb()gate; the fix is purely at bundle time.Why not the other half of MOBILE-402?
The ticket title also references "env var detection" — Sam's complaint that
EXPO_PUBLIC_CLERK_PUBLISHABLE_KEYauto-detection fails in EAS prod. That was already resolved in #7655:publishableKeyis now a required prop, env-var fallbacks were removed entirely, and the JSDoc explains why (env vars in node_modules aren't inlined in production builds). Sam's workaround is now the official path.Test plan
expo-web-browserinstalled, install@clerk/clerk-expofrom this branch, runnpx expo export --platform ios— bundling should complete (previously failed)expo-web-browserinstalled — verify SSO/OAuth flow still worksLinear
MOBILE-402