From 589db9ebf0dbcbd74d089ff52dec9480f4fd4439 Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Tue, 19 May 2026 15:05:29 +0200 Subject: [PATCH 1/2] fix(core): Preserve Metro config object identity in serializer wrapper Co-Authored-By: Claude Opus 4.6 --- .../src/js/tools/sentryOptionsSerializer.ts | 16 ++++--- .../tools/sentryOptionsSerializer.test.ts | 47 +++++++++++++++++++ 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/packages/core/src/js/tools/sentryOptionsSerializer.ts b/packages/core/src/js/tools/sentryOptionsSerializer.ts index f30b144394..d9aa62c35a 100644 --- a/packages/core/src/js/tools/sentryOptionsSerializer.ts +++ b/packages/core/src/js/tools/sentryOptionsSerializer.ts @@ -57,13 +57,15 @@ export function withSentryOptionsFromFile(config: MetroConfig, optionsFile: stri return originalSerializer(entryPoint, preModules, graph, options); }; - return { - ...config, - serializer: { - ...config.serializer, - customSerializer: sentryOptionsSerializer, - }, - }; + // Preserve Expo's __originalSerializer marker so Expo can detect user-provided serializers + if ('__originalSerializer' in originalSerializer) { + Object.assign(sentryOptionsSerializer, { + __originalSerializer: (originalSerializer as Record).__originalSerializer, + }); + } + + config.serializer.customSerializer = sentryOptionsSerializer; + return config; } function createSentryOptionsModule(filePath: string): Module | null { diff --git a/packages/core/test/tools/sentryOptionsSerializer.test.ts b/packages/core/test/tools/sentryOptionsSerializer.test.ts index 8027ff1953..f558e05618 100644 --- a/packages/core/test/tools/sentryOptionsSerializer.test.ts +++ b/packages/core/test/tools/sentryOptionsSerializer.test.ts @@ -165,6 +165,53 @@ describe('Sentry Options Serializer', () => { expect(actualResult).toEqual(mockedResult); }); + test('mutates config in place to preserve object identity for Expo serializer closures', () => { + const config = { + projectRoot: '/test', + serializer: { + customSerializer: customSerializerMock, + getModulesRunBeforeMainModule: jest.fn(), + }, + }; + const originalSerializerObj = config.serializer; + + const result = withSentryOptionsFromFile(config, true); + + expect(result).toBe(config); + expect(result.serializer).toBe(originalSerializerObj); + expect(result.serializer?.customSerializer).not.toBe(customSerializerMock); + expect(result.serializer?.getModulesRunBeforeMainModule).toBe(config.serializer.getModulesRunBeforeMainModule); + }); + + test('preserves __originalSerializer marker from Expo serializer', () => { + const expoSerializer = Object.assign(jest.fn(), { __originalSerializer: null }); + const config = { + projectRoot: '/test', + serializer: { + customSerializer: expoSerializer, + }, + }; + + const result = withSentryOptionsFromFile(config, true); + + expect('__originalSerializer' in (result.serializer?.customSerializer as Record)).toBe(true); + expect((result.serializer?.customSerializer as Record).__originalSerializer).toBeNull(); + }); + + test('does not add __originalSerializer when original serializer lacks it', () => { + const plainSerializer = jest.fn(); + const config = { + projectRoot: '/test', + serializer: { + customSerializer: plainSerializer, + }, + }; + + const result = withSentryOptionsFromFile(config, true); + + expect('__originalSerializer' in (result.serializer?.customSerializer as Record)).toBe(false); + }); + test('uses custom file path when optionsFile is a string', () => { const config = () => ({ projectRoot: '/test', From be48b926f10c972c4334baf1330d5a3c8daf79e5 Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Tue, 19 May 2026 15:06:20 +0200 Subject: [PATCH 2/2] docs(changelog): Add changelog entry for #6188 Co-Authored-By: Claude Opus 4.6 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb3e7e49d0..583e2c6c3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ - Fix boolean options from `sentry.options.json` being ignored on Android when using `RNSentrySDK.init` ([#6130](https://github.com/getsentry/sentry-react-native/pull/6130)) - Fix `includeWebFeedback: false` Metro config option causing crash at startup ([#6150](https://github.com/getsentry/sentry-react-native/pull/6150)) - Fix `sentry-expo-upload-sourcemaps` failing for projects with `devEngines.packageManager` set to non-npm managers ([#6155](https://github.com/getsentry/sentry-react-native/pull/6155)) +- Fix Metro serializer wrapper breaking `getModulesRunBeforeMainModule` for third-party plugins like `react-native-worklets` `bundleMode` ([#6188](https://github.com/getsentry/sentry-react-native/pull/6188)) ### Dependencies