Repository navigation
Don't throw when the module is imported outside the native runtime - #478
Draft
niamh-coleman wants to merge 1 commit into
Draft
niamh-coleman wants to merge 1 commit into
niamh-coleman wants to merge 1 commit into
Conversation
Importing the package read native module properties at load time: IntercomEvents read its event names from IntercomEventEmitter, and setNeedsStatusBarAppearanceUpdate read its method from IntercomModule while building the Platform.select object. Outside the native runtime those modules are undefined, so the import threw. Expo Router's server export evaluates every route file in Node, which broke the iOS Release build of a default Expo app that imports the package in a route or layout. Both reads now happen safely, and the values in the app are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Why?
Importing
@intercom/intercom-react-nativein an Expo Router route or layout file breaks the iOS Release build of a default Expo SDK 58 app. The default template setsweb.output: "server", so the "Bundle React Native code and images" build step also exports server code, and that export evaluates every route file in Node. There the import throws:The module read native module properties at load time, and outside the native runtime those modules are undefined.
How?
Two reads happened at import, and both now happen safely:
IntercomEventsread its event names fromIntercomEventEmitter. They now use optional chaining, so in the app they are the same native constants, and outside it they areundefined.setNeedsStatusBarAppearanceUpdatereadIntercomModule.setNeedsStatusBarAppearanceUpdatewhile building thePlatform.selectobject, which evaluates every branch. It now calls the method when invoked, like the other methods do.A new test imports the module without
IntercomEventEmitterorIntercomModuleinNativeModules. It also checks that the event names and the status bar method still come from the native modules when they exist.Notes for reviewers
IntercomEventEmitteronly exports the unread count and JWT constants, soIntercomWindowDidHideandIntercomWindowDidShowwere alreadyundefinedthere, and still are.mainwith the TypeError above and passes with this change. Locally it ran against newer jest, React Native and TypeScript than the pinned ones, and ESLint didn't run, so CI is the check against the pinned versions.🤖 Generated with Claude Code