Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/core/src/metro/__tests__/metro.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ describe('Datadog Metro Plugin', () => {
});

describe('Datadog Metro Serializer', () => {
test('skips debug ID injection for web platform builds', async () => {
const serializer = createDatadogMetroSerializer();
const args = mockSerializerArgsForEmptyModule();
// Set platform to 'web'
(args[2] as any).transformOptions.platform = 'web';

const bundle = await serializer(...args);
const { code } = await convertSerializerOutput(bundle);
// Web builds should not contain debug ID injection
expect(code).not.toContain('debugId');
Comment thread
cdn34dd marked this conversation as resolved.
expect(code).not.toContain('_datadogDebugIds');
});

test('generates bundle and source map with UUID v5 Debug ID', async () => {
const codeSnippetHash = createHash('md5');
codeSnippetHash.update(DEBUG_ID_CODE_SNIPPET);
Expand Down
14 changes: 11 additions & 3 deletions packages/core/src/metro/plugin/metroSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ export const createDatadogMetroSerializer = (
): DatadogMetroSerializer => {
const serializer = customSerializer || createDefaultMetroSerializer();
return async (entryPoint, preModules, graph, options) => {
// Skip for hot reload mode
if ((graph.transformOptions as any).hot) {
// Skip for hot reload mode and web builds
if (
(graph.transformOptions as any).hot ||
graph.transformOptions.platform === 'web'
) {
return serializer(entryPoint, preModules, graph, options);
}

Expand Down Expand Up @@ -158,14 +161,19 @@ export const createDatadogBundleCallback = (
* Adds Debug ID module for runtime injection, used for Expo.
*/
export function unstable_beforeAssetSerializationPlugin({
graph,
premodules,
debugId
}: {
graph: ReadOnlyGraph<MixedOutput>;
premodules: Module[];
debugId?: string;
}): Module[] {
if (!debugId || checkIfDebugIdModuleExists(premodules)) {
if (
graph.transformOptions.platform === 'web' ||
!debugId ||
checkIfDebugIdModuleExists(premodules)
) {
Comment thread
cdn34dd marked this conversation as resolved.
return premodules;
}
return [...addDebugIdModule(premodules, createDebugIdModule(debugId))];
Expand Down
8 changes: 8 additions & 0 deletions packages/react-native-babel-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ export default declare(
Program: {
enter(path, state) {
const pluginState: PluginPassState = state;

// Skip all transforms for web builds
const platform = (state.file?.opts?.caller as any)
?.platform;
if (platform === 'web') {
return;
}

Comment thread
cdn34dd marked this conversation as resolved.
const { path: p, name } = getFileInfo(this);

if (p?.includes('node_modules')) {
Expand Down
32 changes: 32 additions & 0 deletions packages/react-native-babel-plugin/test/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,38 @@ describe('Babel plugin: initialization', () => {
});
});

describe('Babel plugin: web platform', () => {
it('should skip all transforms for web platform builds', () => {
const input = `
import { Button } from 'react-native';
<Button color="red" onPress={func} />
`;
const output = transform(input, {
filename: 'file.tsx',
presets: ['@babel/preset-react', '@babel/preset-typescript'],
plugins: [
[
plugin,
{
components: {
useContent: true,
useNamePrefix: true,
tracked: []
},
sessionReplay: { svgTracking: false }
}
]
],
configFile: false,
caller: { name: 'metro', platform: 'web' }
})?.code;
// Should not inject Datadog imports or wrappers
expect(output).not.toContain('DdBabelInteractionTracking');
expect(output).not.toContain('__DD_RN_BABEL_PLUGIN_ENABLED__');
expect(output).not.toContain('@datadog/mobile-react-native');
});
});

describe('Babel plugin: wrap interaction handlers for RUM', () => {
it('should not wrap unsupported property (onClick) on supported element (Button)', () => {
const input = `
Expand Down
Loading