Skip to content

Commit b815ca9

Browse files
antonisclaude
andcommitted
fix(babel): Guard against null in autoInjectSentryLabel and restore non-text wrapper behavior
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0e5c99c commit b815ca9

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

packages/babel-plugin-component-annotate/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ function createJSXProcessingContext(
187187
fragmentContext: state.sentryFragmentContext,
188188
autoInjectSentryLabel: !!state.opts.autoInjectSentryLabel,
189189
textComponentNames:
190-
(typeof state.opts.autoInjectSentryLabel === "object"
190+
(state.opts.autoInjectSentryLabel && typeof state.opts.autoInjectSentryLabel === "object"
191191
? state.opts.autoInjectSentryLabel.textComponentNames
192192
: undefined) ?? DEFAULT_TEXT_COMPONENT_NAMES,
193193
};
@@ -790,7 +790,6 @@ function extractTextFromTextComponent(
790790
if (innerTexts === null) {
791791
return null;
792792
}
793-
texts.push(...innerTexts);
794793
}
795794
} else if (t.isJSXFragment(child)) {
796795
const innerTexts = extractTextFromTextComponent(t, child, textComponentNames);

packages/babel-plugin-component-annotate/test/sentry-label.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,20 +571,20 @@ describe("autoInjectSentryLabel", () => {
571571
expect(result?.code).toContain('"sentry-label": "Hello World more"');
572572
});
573573

574-
it("extracts text from non-text wrapper inside Text", () => {
574+
it("handles Text wrapping only a non-text element", () => {
575575
const result = transformWith(`
576576
import React from 'react';
577577
import { Text, View } from 'react-native';
578578
579579
export default function MyComponent() {
580580
return (
581581
<View>
582-
<Text>Hello <Bold>world</Bold></Text>
582+
<Text><Bold>hello</Bold></Text>
583583
</View>
584584
);
585585
}
586586
`);
587-
expect(result?.code).toContain('"sentry-label": "Hello world"');
587+
expect(result?.code).not.toContain("sentry-label");
588588
});
589589
});
590590

0 commit comments

Comments
 (0)