diff --git a/src/FSPage.ts b/src/FSPage.ts index a6b86ce..f2c4cff 100644 --- a/src/FSPage.ts +++ b/src/FSPage.ts @@ -10,7 +10,11 @@ const FullStory = isTurboModuleEnabled ? require('./NativeFullStory').default : NativeModules.FullStory; -const { startPage, endPage, updatePage } = FullStory; +const { startPage, endPage, updatePage } = FullStory || { + startPage: () => null, + endPage: () => null, + updatePage: () => null, +}; type UnknownObj = { [key: string]: unknown | UnknownObj; diff --git a/src/index.ts b/src/index.ts index 7c0c833..79f2a46 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,6 +18,10 @@ const FullStory = isTurboModuleEnabled ? require('./NativeFullStory').default : NativeModules.FullStory; +if (!FullStory) { + console.warn('FullStory: Native module not found. Falling back to stub implementations.'); +} + const { anonymize, identify, @@ -31,7 +35,20 @@ const { restart, log, resetIdleTimer, -} = FullStory; +} = FullStory || { + anonymize: () => null, + identify: () => null, + setUserVars: () => null, + onReady: () => Promise.resolve({ replayStartUrl: '', replayNowUrl: '', sessionId: '' }), + getCurrentSession: () => Promise.resolve(''), + getCurrentSessionURL: () => Promise.resolve(''), + consent: () => null, + event: () => null, + shutdown: () => null, + restart: () => null, + log: () => null, + resetIdleTimer: () => null, +}; const FullStoryPrivate = isTurboModuleEnabled ? require('./NativeFullStoryPrivate').default @@ -60,7 +77,7 @@ interface NativeCommands { dataComponent: (viewRef: ComponentRef, dataElement: string) => void; } -/* +/* Calling these commands sequentially will *not* lead to an intermediate state where views have incomplete attribute values. React's rendering phases protects against this race condition. See DOC-1863 for more information. @@ -98,7 +115,7 @@ type FSNativeElement = ComponentRef & { // Shared wrapper for components without refs (most common case) function sharedRefWrapper(element: FSNativeElement | null) { - if (element && isTurboModuleEnabled && Platform.OS === 'ios') { + if (element && isTurboModuleEnabled && Platform.OS === 'ios' && !Platform.isTV) { let currentProps: Record; if (getInternalInstanceHandleFromPublicInstance) {