Skip to content

Commit

Permalink
fix(expo-web): Multiple Debug IDs can be loaded into the global polyf…
Browse files Browse the repository at this point in the history
…ill (#3660)
  • Loading branch information
krystofwoldrich committed Mar 7, 2024
1 parent d1753bd commit 8cabbfa
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

### Fixes

- Multiple Debug IDs can be loaded into the global polyfill ([#3660](https://github.com/getsentry/sentry-react-native/pull/3660))
- This fixes a symbolication issue with Expo on the web with enabled bundle splitting.

### Dependencies

- Bump CLI from v2.25.2 to v2.29.1 ([#3534](https://github.com/getsentry/sentry-react-native/pull/3534))
Expand Down
4 changes: 2 additions & 2 deletions scripts/sentry-debugid-injection-snippet.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This is non minified version the debug id injection snippet used in the Metro plugin.
var _sentryDebugIds = {};
var _sentryDebugIdIdentifier = '';
var _sentryDebugIds;
var _sentryDebugIdIdentifier;

if (typeof _sentryDebugIds === 'undefined') {
_sentryDebugIds = {};
Expand Down
2 changes: 1 addition & 1 deletion src/js/tools/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export type MetroSerializer = (
* Returns minified Debug ID code snippet.
*/
export function createDebugIdSnippet(debugId: string): string {
return `var _sentryDebugIds={},_sentryDebugIdIdentifier="";void 0===_sentryDebugIds&&(_sentryDebugIds={});try{var stack=(new Error).stack;stack&&(_sentryDebugIds[stack]="${debugId}",_sentryDebugIdIdentifier="sentry-dbid-${debugId}")}catch(e){}`;
return `var _sentryDebugIds,_sentryDebugIdIdentifier;void 0===_sentryDebugIds&&(_sentryDebugIds={});try{var stack=(new Error).stack;stack&&(_sentryDebugIds[stack]="${debugId}",_sentryDebugIdIdentifier="sentry-dbid-${debugId}")}catch(e){}`;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions test/tools/fixtures/bundleWithPrelude.js.fixture
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__mock_prelude__
var _sentryDebugIds={},_sentryDebugIdIdentifier="";void 0===_sentryDebugIds&&(_sentryDebugIds={});try{var stack=(new Error).stack;stack&&(_sentryDebugIds[stack]="d2b7a793-6dd9-4802-9250-9cc0c54f8c23",_sentryDebugIdIdentifier="sentry-dbid-d2b7a793-6dd9-4802-9250-9cc0c54f8c23")}catch(e){}
var _sentryDebugIds,_sentryDebugIdIdentifier;void 0===_sentryDebugIds&&(_sentryDebugIds={});try{var stack=(new Error).stack;stack&&(_sentryDebugIds[stack]="a4917c7b-23c2-46db-b503-1079d8bccbc6",_sentryDebugIdIdentifier="sentry-dbid-a4917c7b-23c2-46db-b503-1079d8bccbc6")}catch(e){}
__mock_index_js__
//# debugId=d2b7a793-6dd9-4802-9250-9cc0c54f8c23
//# debugId=a4917c7b-23c2-46db-b503-1079d8bccbc6
2 changes: 1 addition & 1 deletion test/tools/fixtures/bundleWithPrelude.js.fixture.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions test/tools/sentryMetroSerializer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ describe('Sentry Metro Serializer', () => {
}

expect(bundle.code).toEqual(
'var _sentryDebugIds={},_sentryDebugIdIdentifier="";void 0===_sentryDebugIds&&(_sentryDebugIds={});try{var stack=(new Error).stack;stack&&(_sentryDebugIds[stack]="901c00b1-71e1-40fc-b787-3fe0a7e23a92",_sentryDebugIdIdentifier="sentry-dbid-901c00b1-71e1-40fc-b787-3fe0a7e23a92")}catch(e){}\n//# debugId=901c00b1-71e1-40fc-b787-3fe0a7e23a92',
'var _sentryDebugIds,_sentryDebugIdIdentifier;void 0===_sentryDebugIds&&(_sentryDebugIds={});try{var stack=(new Error).stack;stack&&(_sentryDebugIds[stack]="c9e276ed-1171-4e26-ac5d-0193a85ed160",_sentryDebugIdIdentifier="sentry-dbid-c9e276ed-1171-4e26-ac5d-0193a85ed160")}catch(e){}\n//# debugId=c9e276ed-1171-4e26-ac5d-0193a85ed160',
);
expect(bundle.map).toEqual(
'{"version":3,"sources":["__debugid__"],"sourcesContent":["var _sentryDebugIds={},_sentryDebugIdIdentifier=\\"\\";void 0===_sentryDebugIds&&(_sentryDebugIds={});try{var stack=(new Error).stack;stack&&(_sentryDebugIds[stack]=\\"901c00b1-71e1-40fc-b787-3fe0a7e23a92\\",_sentryDebugIdIdentifier=\\"sentry-dbid-901c00b1-71e1-40fc-b787-3fe0a7e23a92\\")}catch(e){}"],"names":[],"mappings":"","debug_id":"901c00b1-71e1-40fc-b787-3fe0a7e23a92","debugId":"901c00b1-71e1-40fc-b787-3fe0a7e23a92"}',
'{"version":3,"sources":["__debugid__"],"sourcesContent":["var _sentryDebugIds,_sentryDebugIdIdentifier;void 0===_sentryDebugIds&&(_sentryDebugIds={});try{var stack=(new Error).stack;stack&&(_sentryDebugIds[stack]=\\"c9e276ed-1171-4e26-ac5d-0193a85ed160\\",_sentryDebugIdIdentifier=\\"sentry-dbid-c9e276ed-1171-4e26-ac5d-0193a85ed160\\")}catch(e){}"],"names":[],"mappings":"","debug_id":"c9e276ed-1171-4e26-ac5d-0193a85ed160","debugId":"c9e276ed-1171-4e26-ac5d-0193a85ed160"}',
);
});

test('generated debug id is uuid v4 format', async () => {
const serializer = createSentryMetroSerializer();
const bundle = await serializer(...mockMinSerializerArgs());
const debugId = determineDebugIdFromBundleSource(typeof bundle === 'string' ? bundle : bundle.code);
expect(debugId).toEqual('901c00b1-71e1-40fc-b787-3fe0a7e23a92');
expect(debugId).toEqual('c9e276ed-1171-4e26-ac5d-0193a85ed160');
});

test('adds debug id snipped after prelude module and before ', async () => {
Expand Down

0 comments on commit 8cabbfa

Please sign in to comment.