@datadog/mobile-react-native 1.1.3 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js +3 -8
- package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/getJsxRuntime.js +58 -0
- package/lib/commonjs/rum/instrumentation/getJsxRuntime.js.map +1 -0
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js +2 -8
- package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/getJsxRuntime.js +48 -0
- package/lib/module/rum/instrumentation/getJsxRuntime.js.map +1 -0
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/rum/instrumentation/getJsxRuntime.d.ts +1 -0
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +5 -3
- package/scripts/replace-react-require.js +78 -0
- package/src/rum/instrumentation/DdRumUserInteractionTracking.tsx +2 -8
- package/src/rum/instrumentation/getJsxRuntime.ts +43 -0
- package/src/version.ts +1 -1
|
@@ -17,6 +17,8 @@ var _NoOpEventsInterceptor = _interopRequireDefault(require("./NoOpEventsInterce
|
|
|
17
17
|
|
|
18
18
|
var _ShallowObjectEqualityChecker = require("./ShallowObjectEqualityChecker");
|
|
19
19
|
|
|
20
|
+
var _getJsxRuntime = require("./getJsxRuntime");
|
|
21
|
+
|
|
20
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
23
|
|
|
22
24
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -47,16 +49,9 @@ class DdRumUserInteractionTracking {
|
|
|
47
49
|
};
|
|
48
50
|
|
|
49
51
|
try {
|
|
50
|
-
|
|
51
|
-
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
52
|
-
const jsxRuntime = require('react/jsx-runtime');
|
|
53
|
-
|
|
52
|
+
const jsxRuntime = (0, _getJsxRuntime.getJsxRuntime)();
|
|
54
53
|
const originaljsx = jsxRuntime.jsx;
|
|
55
54
|
|
|
56
|
-
if (!originaljsx) {
|
|
57
|
-
throw new Error('React version does not support new jsx transform');
|
|
58
|
-
}
|
|
59
|
-
|
|
60
55
|
jsxRuntime.jsx = (...args) => {
|
|
61
56
|
return this.patchCreateElementFunction(originaljsx, args);
|
|
62
57
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["DdRumUserInteractionTracking.tsx"],"names":["DdRumUserInteractionTracking","startTracking","isTracking","InternalLog","log","SdkVerbosity","WARN","eventsInterceptor","DdEventsInterceptor","original","React","createElement","args","patchCreateElementFunction","jsxRuntime","
|
|
1
|
+
{"version":3,"sources":["DdRumUserInteractionTracking.tsx"],"names":["DdRumUserInteractionTracking","startTracking","isTracking","InternalLog","log","SdkVerbosity","WARN","eventsInterceptor","DdEventsInterceptor","original","React","createElement","args","patchCreateElementFunction","jsxRuntime","originaljsx","jsx","e","originalMemo","memo","component","propsAreEqual","prev","next","onPress","_prevOnPress","partialPrevProps","prevProps","__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__","_nextOnPress","partialNextProps","nextProps","INFO","NoOpEventsInterceptor","originalFunction","element","props","rest","originalOnPress","interceptOnPress"],"mappings":";;;;;;;AAMA;;AAEA;;AACA;;AAEA;;AAEA;;AACA;;AACA;;;;;;AAEA;AACA;AACA;AACA;AACO,MAAMA,4BAAN,CAAmC;AA6BtC;AACJ;AACA;AACA;AACA;AACwB,SAAbC,aAAa,GAAS;AACzB;AACA,QAAID,4BAA4B,CAACE,UAAjC,EAA6C;AACzCC,+BAAYC,GAAZ,CACI,8CADJ,EAEIC,2BAAaC,IAFjB;;A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,CAACK;AAFA,SAAlB,CAd2C,CAmB3C;;AACA,eAAOP,aAAa,GACdA,aAAa,CAACM,SAAD,EAAYI,SAAZ,CADC,GAEd,yDAAsBA,SAAtB,EAAiCJ,SAAjC,CAFN;AAGH,OAvBkB,CAAnB;AAwBH,KA5BD;;AA8BA3B,IAAAA,4BAA4B,CAACE,UAA7B,GAA0C,IAA1C;;AACAC,6BAAYC,GAAZ,CACI,sCADJ,EAEIC,2BAAa2B,IAFjB;AAIH;;AApGqC;;;;gBAA7BhC,4B,gBACmB,K;;gBADnBA,4B,uBAE6C,IAAIiC,8BAAJ,E;;gBAF7CjC,4B,gCAImC,CACxCkC,gBADwC,EAExC,CAACC,OAAD,EAAUC,KAAV,EAAiB,GAAGC,IAApB,CAFwC,KAGC;AACzC,MACID,KAAK,IACL,OAAQA,KAAD,CAAmCZ,OAA1C,KAAsD,UAF1D,EAGE;AACE,UAAMc,eAAe,GAAIF,KAAD,EAAmC;AACtDZ,IAAAA,OADL;;AAECY,IAAAA,KAAD,CAAmCZ,OAAnC,GAA6C,CAAC,GAAGZ,IAAJ,KAAoB;AAC7DZ,MAAAA,4BAA4B,CAACO,iBAA7B,CAA+CgC,gBAA/C,CACI,GAAG3B,IADP;AAGA,aAAO0B,eAAe,CAAC,GAAG1B,IAAJ,CAAtB;AACH,KALD,CAHF,CASE;;;AACCwB,IAAAA,KAAD,CAGGR,sCAHH,GAG4CU,eAH5C;AAIH;;AACD,SAAOJ,gBAAgB,CAACC,OAAD,EAAUC,KAAV,EAAiB,GAAGC,IAApB,CAAvB;AACH,C","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport React from 'react';\n\nimport { InternalLog } from '../../InternalLog';\nimport { SdkVerbosity } from '../../SdkVerbosity';\n\nimport { DdEventsInterceptor } from './DdEventsInterceptor';\nimport type EventsInterceptor from './EventsInterceptor';\nimport NoOpEventsInterceptor from './NoOpEventsInterceptor';\nimport { areObjectShallowEqual } from './ShallowObjectEqualityChecker';\nimport { getJsxRuntime } from './getJsxRuntime';\n\n/**\n * Provides RUM auto-instrumentation feature to track user interaction as RUM events.\n * For now we are only covering the \"onPress\" events.\n */\nexport class DdRumUserInteractionTracking {\n private static isTracking = false;\n private static eventsInterceptor: EventsInterceptor = new NoOpEventsInterceptor();\n\n private static patchCreateElementFunction = (\n originalFunction: typeof React.createElement,\n [element, props, ...rest]: Parameters<typeof React.createElement>\n ): ReturnType<typeof React.createElement> => {\n if (\n props &&\n typeof (props as Record<string, unknown>).onPress === 'function'\n ) {\n const originalOnPress = (props as Record<string, unknown>) // eslint-disable-next-line @typescript-eslint/ban-types\n .onPress as Function;\n (props as Record<string, unknown>).onPress = (...args: any[]) => {\n DdRumUserInteractionTracking.eventsInterceptor.interceptOnPress(\n ...args\n );\n return originalOnPress(...args);\n };\n // we store the original onPress prop so we can keep memoization working\n (props as Record<\n string,\n unknown\n >).__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__ = originalOnPress;\n }\n return originalFunction(element, props, ...rest);\n };\n\n /**\n * Starts tracking user interactions and sends a RUM Action event every time a new interaction was detected.\n * Please note that we are only considering as valid - for - tracking only the user interactions that have\n * a visible output (either an UI state change or a Resource request)\n */\n static startTracking(): void {\n // extra safety to avoid wrapping more than 1 time this function\n if (DdRumUserInteractionTracking.isTracking) {\n InternalLog.log(\n 'Datadog SDK is already tracking interactions',\n SdkVerbosity.WARN\n );\n return;\n }\n DdRumUserInteractionTracking.eventsInterceptor = new DdEventsInterceptor();\n\n const original = React.createElement;\n React.createElement = (\n ...args: Parameters<typeof React.createElement>\n ): any => {\n return this.patchCreateElementFunction(original, args);\n };\n\n try {\n const jsxRuntime = getJsxRuntime();\n const originaljsx = jsxRuntime.jsx;\n jsxRuntime.jsx = (\n ...args: Parameters<typeof React.createElement>\n ): ReturnType<typeof React.createElement> => {\n return this.patchCreateElementFunction(originaljsx, args);\n };\n } catch (e) {\n // TODO: Add telemetry\n }\n\n const originalMemo = React.memo;\n React.memo = (\n component: any,\n propsAreEqual?: (prevProps: any, newProps: any) => boolean\n ) => {\n return originalMemo(component, (prev, next) => {\n if (!next.onPress || !prev.onPress) {\n return propsAreEqual\n ? propsAreEqual(prev, next)\n : areObjectShallowEqual(prev, next);\n }\n // we replace \"our\" onPress from the props by the original for comparison\n const { onPress: _prevOnPress, ...partialPrevProps } = prev;\n const prevProps = {\n ...partialPrevProps,\n onPress: prev.__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__\n };\n\n const { onPress: _nextOnPress, ...partialNextProps } = next;\n const nextProps = {\n ...partialNextProps,\n onPress: next.__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__\n };\n\n // if no comparison function is provided we do shallow comparison\n return propsAreEqual\n ? propsAreEqual(prevProps, nextProps)\n : areObjectShallowEqual(nextProps, prevProps);\n });\n };\n\n DdRumUserInteractionTracking.isTracking = true;\n InternalLog.log(\n 'Datadog SDK is tracking interactions',\n SdkVerbosity.INFO\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getJsxRuntime = void 0;
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
10
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
11
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
12
|
+
*/
|
|
13
|
+
const getJsxRuntime = () => {
|
|
14
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
15
|
+
const [major, minor] = require('react/package.json').version.split('.'); // We need to check on the version of React before requiring 'react/jsx-runtime') as
|
|
16
|
+
// it might crash other exports if the export does not exist (even if there is a try/catch).
|
|
17
|
+
// See: https://github.com/facebook/metro/issues/836
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
if (!isJsxExportedInReactVersion(major, minor)) {
|
|
21
|
+
throw new Error('React version does not support new jsx transform');
|
|
22
|
+
} // /!\/!\/!\/!\/!\/!\
|
|
23
|
+
// We have to use inline require here because older React versions (below 16.14) don't have jsx-runtime.
|
|
24
|
+
// metro does not support dynamic require, so 'react/jsx-runtime' is replaced by 'react' on postinstall
|
|
25
|
+
// when react is equal or above 16.14 to avoid this require call to fail during the import phase and then
|
|
26
|
+
// disable all further imports.
|
|
27
|
+
// /!\/!\/!\/!\/!\/!\
|
|
28
|
+
//
|
|
29
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
33
|
+
|
|
34
|
+
if (!jsxRuntime.jsx) {
|
|
35
|
+
throw new Error('React version does not support new jsx transform');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return jsxRuntime;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* JSX Transform is available for React 16.14.0 (last React 16 version) and above
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
exports.getJsxRuntime = getJsxRuntime;
|
|
46
|
+
|
|
47
|
+
const isJsxExportedInReactVersion = (major, minor) => {
|
|
48
|
+
if (Number(major) > 16) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (Number(major) === 16 && Number(minor) > 13) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return false;
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=getJsxRuntime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["getJsxRuntime.ts"],"names":["getJsxRuntime","major","minor","require","version","split","isJsxExportedInReactVersion","Error","jsxRuntime","jsx","Number"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AAEO,MAAMA,aAAa,GAAG,MAAM;AAC/B;AACA,QAAM,CAACC,KAAD,EAAQC,KAAR,IAAiBC,OAAO,CAAC,oBAAD,CAAP,CAA8BC,OAA9B,CAAsCC,KAAtC,CAA4C,GAA5C,CAAvB,CAF+B,CAG/B;AACA;AACA;;;AACA,MAAI,CAACC,2BAA2B,CAACL,KAAD,EAAQC,KAAR,CAAhC,EAAgD;AAC5C,UAAM,IAAIK,KAAJ,CAAU,kDAAV,CAAN;AACH,GAR8B,CAU/B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,QAAMC,UAAU,GAAGL,OAAO,CAAC,mBAAD,CAA1B;;AACA,MAAI,CAACK,UAAU,CAACC,GAAhB,EAAqB;AACjB,UAAM,IAAIF,KAAJ,CAAU,kDAAV,CAAN;AACH;;AACD,SAAOC,UAAP;AACH,CAvBM;AAyBP;AACA;AACA;;;;;AACA,MAAMF,2BAA2B,GAAG,CAACL,KAAD,EAAgBC,KAAhB,KAA2C;AAC3E,MAAIQ,MAAM,CAACT,KAAD,CAAN,GAAgB,EAApB,EAAwB;AACpB,WAAO,IAAP;AACH;;AACD,MAAIS,MAAM,CAACT,KAAD,CAAN,KAAkB,EAAlB,IAAwBS,MAAM,CAACR,KAAD,CAAN,GAAgB,EAA5C,EAAgD;AAC5C,WAAO,IAAP;AACH;;AACD,SAAO,KAAP;AACH,CARD","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nexport const getJsxRuntime = () => {\n // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires\n const [major, minor] = require('react/package.json').version.split('.');\n // We need to check on the version of React before requiring 'react/jsx-runtime') as\n // it might crash other exports if the export does not exist (even if there is a try/catch).\n // See: https://github.com/facebook/metro/issues/836\n if (!isJsxExportedInReactVersion(major, minor)) {\n throw new Error('React version does not support new jsx transform');\n }\n\n // /!\\/!\\/!\\/!\\/!\\/!\\\n // We have to use inline require here because older React versions (below 16.14) don't have jsx-runtime.\n // metro does not support dynamic require, so 'react/jsx-runtime' is replaced by 'react' on postinstall\n // when react is equal or above 16.14 to avoid this require call to fail during the import phase and then\n // disable all further imports.\n // /!\\/!\\/!\\/!\\/!\\/!\\\n //\n // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires\n const jsxRuntime = require('react/jsx-runtime');\n if (!jsxRuntime.jsx) {\n throw new Error('React version does not support new jsx transform');\n }\n return jsxRuntime;\n};\n\n/**\n * JSX Transform is available for React 16.14.0 (last React 16 version) and above\n */\nconst isJsxExportedInReactVersion = (major: string, minor: string): boolean => {\n if (Number(major) > 16) {\n return true;\n }\n if (Number(major) === 16 && Number(minor) > 13) {\n return true;\n }\n return false;\n};\n"]}
|
package/lib/commonjs/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["version.ts"],"names":["version"],"mappings":";;;;;;AAAA;AACO,MAAMA,OAAO,GAAG,OAAhB","sourcesContent":["// generated by genversion\nexport const version = '1.1.
|
|
1
|
+
{"version":3,"sources":["version.ts"],"names":["version"],"mappings":";;;;;;AAAA;AACO,MAAMA,OAAO,GAAG,OAAhB","sourcesContent":["// generated by genversion\nexport const version = '1.1.5';\n"]}
|
|
@@ -11,6 +11,7 @@ import { SdkVerbosity } from '../../SdkVerbosity';
|
|
|
11
11
|
import { DdEventsInterceptor } from './DdEventsInterceptor';
|
|
12
12
|
import NoOpEventsInterceptor from './NoOpEventsInterceptor';
|
|
13
13
|
import { areObjectShallowEqual } from './ShallowObjectEqualityChecker';
|
|
14
|
+
import { getJsxRuntime } from './getJsxRuntime';
|
|
14
15
|
/**
|
|
15
16
|
* Provides RUM auto-instrumentation feature to track user interaction as RUM events.
|
|
16
17
|
* For now we are only covering the "onPress" events.
|
|
@@ -37,16 +38,9 @@ export class DdRumUserInteractionTracking {
|
|
|
37
38
|
};
|
|
38
39
|
|
|
39
40
|
try {
|
|
40
|
-
|
|
41
|
-
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
42
|
-
const jsxRuntime = require('react/jsx-runtime');
|
|
43
|
-
|
|
41
|
+
const jsxRuntime = getJsxRuntime();
|
|
44
42
|
const originaljsx = jsxRuntime.jsx;
|
|
45
43
|
|
|
46
|
-
if (!originaljsx) {
|
|
47
|
-
throw new Error('React version does not support new jsx transform');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
44
|
jsxRuntime.jsx = (...args) => {
|
|
51
45
|
return this.patchCreateElementFunction(originaljsx, args);
|
|
52
46
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["DdRumUserInteractionTracking.tsx"],"names":["React","InternalLog","SdkVerbosity","DdEventsInterceptor","NoOpEventsInterceptor","areObjectShallowEqual","DdRumUserInteractionTracking","startTracking","isTracking","log","WARN","eventsInterceptor","original","createElement","args","patchCreateElementFunction","jsxRuntime","
|
|
1
|
+
{"version":3,"sources":["DdRumUserInteractionTracking.tsx"],"names":["React","InternalLog","SdkVerbosity","DdEventsInterceptor","NoOpEventsInterceptor","areObjectShallowEqual","getJsxRuntime","DdRumUserInteractionTracking","startTracking","isTracking","log","WARN","eventsInterceptor","original","createElement","args","patchCreateElementFunction","jsxRuntime","originaljsx","jsx","e","originalMemo","memo","component","propsAreEqual","prev","next","onPress","_prevOnPress","partialPrevProps","prevProps","__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__","_nextOnPress","partialNextProps","nextProps","INFO","originalFunction","element","props","rest","originalOnPress","interceptOnPress"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,OAAOA,KAAP,MAAkB,OAAlB;AAEA,SAASC,WAAT,QAA4B,mBAA5B;AACA,SAASC,YAAT,QAA6B,oBAA7B;AAEA,SAASC,mBAAT,QAAoC,uBAApC;AAEA,OAAOC,qBAAP,MAAkC,yBAAlC;AACA,SAASC,qBAAT,QAAsC,gCAAtC;AACA,SAASC,aA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AAUC,KAAV,EAAiB,GAAGC,IAApB,CAAvB;AACH,C","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport React from 'react';\n\nimport { InternalLog } from '../../InternalLog';\nimport { SdkVerbosity } from '../../SdkVerbosity';\n\nimport { DdEventsInterceptor } from './DdEventsInterceptor';\nimport type EventsInterceptor from './EventsInterceptor';\nimport NoOpEventsInterceptor from './NoOpEventsInterceptor';\nimport { areObjectShallowEqual } from './ShallowObjectEqualityChecker';\nimport { getJsxRuntime } from './getJsxRuntime';\n\n/**\n * Provides RUM auto-instrumentation feature to track user interaction as RUM events.\n * For now we are only covering the \"onPress\" events.\n */\nexport class DdRumUserInteractionTracking {\n private static isTracking = false;\n private static eventsInterceptor: EventsInterceptor = new NoOpEventsInterceptor();\n\n private static patchCreateElementFunction = (\n originalFunction: typeof React.createElement,\n [element, props, ...rest]: Parameters<typeof React.createElement>\n ): ReturnType<typeof React.createElement> => {\n if (\n props &&\n typeof (props as Record<string, unknown>).onPress === 'function'\n ) {\n const originalOnPress = (props as Record<string, unknown>) // eslint-disable-next-line @typescript-eslint/ban-types\n .onPress as Function;\n (props as Record<string, unknown>).onPress = (...args: any[]) => {\n DdRumUserInteractionTracking.eventsInterceptor.interceptOnPress(\n ...args\n );\n return originalOnPress(...args);\n };\n // we store the original onPress prop so we can keep memoization working\n (props as Record<\n string,\n unknown\n >).__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__ = originalOnPress;\n }\n return originalFunction(element, props, ...rest);\n };\n\n /**\n * Starts tracking user interactions and sends a RUM Action event every time a new interaction was detected.\n * Please note that we are only considering as valid - for - tracking only the user interactions that have\n * a visible output (either an UI state change or a Resource request)\n */\n static startTracking(): void {\n // extra safety to avoid wrapping more than 1 time this function\n if (DdRumUserInteractionTracking.isTracking) {\n InternalLog.log(\n 'Datadog SDK is already tracking interactions',\n SdkVerbosity.WARN\n );\n return;\n }\n DdRumUserInteractionTracking.eventsInterceptor = new DdEventsInterceptor();\n\n const original = React.createElement;\n React.createElement = (\n ...args: Parameters<typeof React.createElement>\n ): any => {\n return this.patchCreateElementFunction(original, args);\n };\n\n try {\n const jsxRuntime = getJsxRuntime();\n const originaljsx = jsxRuntime.jsx;\n jsxRuntime.jsx = (\n ...args: Parameters<typeof React.createElement>\n ): ReturnType<typeof React.createElement> => {\n return this.patchCreateElementFunction(originaljsx, args);\n };\n } catch (e) {\n // TODO: Add telemetry\n }\n\n const originalMemo = React.memo;\n React.memo = (\n component: any,\n propsAreEqual?: (prevProps: any, newProps: any) => boolean\n ) => {\n return originalMemo(component, (prev, next) => {\n if (!next.onPress || !prev.onPress) {\n return propsAreEqual\n ? propsAreEqual(prev, next)\n : areObjectShallowEqual(prev, next);\n }\n // we replace \"our\" onPress from the props by the original for comparison\n const { onPress: _prevOnPress, ...partialPrevProps } = prev;\n const prevProps = {\n ...partialPrevProps,\n onPress: prev.__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__\n };\n\n const { onPress: _nextOnPress, ...partialNextProps } = next;\n const nextProps = {\n ...partialNextProps,\n onPress: next.__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__\n };\n\n // if no comparison function is provided we do shallow comparison\n return propsAreEqual\n ? propsAreEqual(prevProps, nextProps)\n : areObjectShallowEqual(nextProps, prevProps);\n });\n };\n\n DdRumUserInteractionTracking.isTracking = true;\n InternalLog.log(\n 'Datadog SDK is tracking interactions',\n SdkVerbosity.INFO\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
+
*/
|
|
6
|
+
export const getJsxRuntime = () => {
|
|
7
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
8
|
+
const [major, minor] = require('react/package.json').version.split('.'); // We need to check on the version of React before requiring 'react/jsx-runtime') as
|
|
9
|
+
// it might crash other exports if the export does not exist (even if there is a try/catch).
|
|
10
|
+
// See: https://github.com/facebook/metro/issues/836
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
if (!isJsxExportedInReactVersion(major, minor)) {
|
|
14
|
+
throw new Error('React version does not support new jsx transform');
|
|
15
|
+
} // /!\/!\/!\/!\/!\/!\
|
|
16
|
+
// We have to use inline require here because older React versions (below 16.14) don't have jsx-runtime.
|
|
17
|
+
// metro does not support dynamic require, so 'react/jsx-runtime' is replaced by 'react' on postinstall
|
|
18
|
+
// when react is equal or above 16.14 to avoid this require call to fail during the import phase and then
|
|
19
|
+
// disable all further imports.
|
|
20
|
+
// /!\/!\/!\/!\/!\/!\
|
|
21
|
+
//
|
|
22
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
26
|
+
|
|
27
|
+
if (!jsxRuntime.jsx) {
|
|
28
|
+
throw new Error('React version does not support new jsx transform');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return jsxRuntime;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* JSX Transform is available for React 16.14.0 (last React 16 version) and above
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
const isJsxExportedInReactVersion = (major, minor) => {
|
|
38
|
+
if (Number(major) > 16) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (Number(major) === 16 && Number(minor) > 13) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return false;
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=getJsxRuntime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["getJsxRuntime.ts"],"names":["getJsxRuntime","major","minor","require","version","split","isJsxExportedInReactVersion","Error","jsxRuntime","jsx","Number"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAEA,OAAO,MAAMA,aAAa,GAAG,MAAM;AAC/B;AACA,QAAM,CAACC,KAAD,EAAQC,KAAR,IAAiBC,OAAO,CAAC,oBAAD,CAAP,CAA8BC,OAA9B,CAAsCC,KAAtC,CAA4C,GAA5C,CAAvB,CAF+B,CAG/B;AACA;AACA;;;AACA,MAAI,CAACC,2BAA2B,CAACL,KAAD,EAAQC,KAAR,CAAhC,EAAgD;AAC5C,UAAM,IAAIK,KAAJ,CAAU,kDAAV,CAAN;AACH,GAR8B,CAU/B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,QAAMC,UAAU,GAAGL,OAAO,CAAC,mBAAD,CAA1B;;AACA,MAAI,CAACK,UAAU,CAACC,GAAhB,EAAqB;AACjB,UAAM,IAAIF,KAAJ,CAAU,kDAAV,CAAN;AACH;;AACD,SAAOC,UAAP;AACH,CAvBM;AAyBP;AACA;AACA;;AACA,MAAMF,2BAA2B,GAAG,CAACL,KAAD,EAAgBC,KAAhB,KAA2C;AAC3E,MAAIQ,MAAM,CAACT,KAAD,CAAN,GAAgB,EAApB,EAAwB;AACpB,WAAO,IAAP;AACH;;AACD,MAAIS,MAAM,CAACT,KAAD,CAAN,KAAkB,EAAlB,IAAwBS,MAAM,CAACR,KAAD,CAAN,GAAgB,EAA5C,EAAgD;AAC5C,WAAO,IAAP;AACH;;AACD,SAAO,KAAP;AACH,CARD","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nexport const getJsxRuntime = () => {\n // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires\n const [major, minor] = require('react/package.json').version.split('.');\n // We need to check on the version of React before requiring 'react/jsx-runtime') as\n // it might crash other exports if the export does not exist (even if there is a try/catch).\n // See: https://github.com/facebook/metro/issues/836\n if (!isJsxExportedInReactVersion(major, minor)) {\n throw new Error('React version does not support new jsx transform');\n }\n\n // /!\\/!\\/!\\/!\\/!\\/!\\\n // We have to use inline require here because older React versions (below 16.14) don't have jsx-runtime.\n // metro does not support dynamic require, so 'react/jsx-runtime' is replaced by 'react' on postinstall\n // when react is equal or above 16.14 to avoid this require call to fail during the import phase and then\n // disable all further imports.\n // /!\\/!\\/!\\/!\\/!\\/!\\\n //\n // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires\n const jsxRuntime = require('react/jsx-runtime');\n if (!jsxRuntime.jsx) {\n throw new Error('React version does not support new jsx transform');\n }\n return jsxRuntime;\n};\n\n/**\n * JSX Transform is available for React 16.14.0 (last React 16 version) and above\n */\nconst isJsxExportedInReactVersion = (major: string, minor: string): boolean => {\n if (Number(major) > 16) {\n return true;\n }\n if (Number(major) === 16 && Number(minor) > 13) {\n return true;\n }\n return false;\n};\n"]}
|
package/lib/module/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["version.ts"],"names":["version"],"mappings":"AAAA;AACA,OAAO,MAAMA,OAAO,GAAG,OAAhB","sourcesContent":["// generated by genversion\nexport const version = '1.1.
|
|
1
|
+
{"version":3,"sources":["version.ts"],"names":["version"],"mappings":"AAAA;AACA,OAAO,MAAMA,OAAO,GAAG,OAAhB","sourcesContent":["// generated by genversion\nexport const version = '1.1.5';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getJsxRuntime: () => any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.1.
|
|
1
|
+
export declare const version = "1.1.5";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datadog/mobile-react-native",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "A client-side React Native module to interact with Datadog",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"datadog",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"files": [
|
|
20
20
|
"src",
|
|
21
21
|
"lib",
|
|
22
|
+
"scripts",
|
|
22
23
|
"android/build.gradle",
|
|
23
24
|
"android/gradle.properties",
|
|
24
25
|
"android/src",
|
|
@@ -39,7 +40,8 @@
|
|
|
39
40
|
"scripts": {
|
|
40
41
|
"test": "jest",
|
|
41
42
|
"lint": "eslint .",
|
|
42
|
-
"prepare": "rm -rf lib && yarn bob build"
|
|
43
|
+
"prepare": "rm -rf lib && yarn bob build",
|
|
44
|
+
"postinstall": "scripts/replace-react-require.js"
|
|
43
45
|
},
|
|
44
46
|
"peerDependencies": {
|
|
45
47
|
"react": ">=16.13.1",
|
|
@@ -73,5 +75,5 @@
|
|
|
73
75
|
]
|
|
74
76
|
]
|
|
75
77
|
},
|
|
76
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "22a120295f0430301fc12bed8393c0243d61b55a"
|
|
77
79
|
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
5
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
6
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* This script replaces the inline require of 'react' in src/rum/instrumentation/getJsxRuntime.ts
|
|
11
|
+
* to 'react/jsx-runtime'.
|
|
12
|
+
*
|
|
13
|
+
* Context:
|
|
14
|
+
* From its version 16.14, React adds the `jsx` function as a new way to create components. This replaces
|
|
15
|
+
* the createElement function (which is still used in current versions in some cases).
|
|
16
|
+
* From React 18, this seems to become the default. This is also used by default in Expo since Expo 45 at least.
|
|
17
|
+
* On React versions below 16.14, trying to import 'react/jsx-runtime' would fail (see https://github.com/facebook/metro/issues/836)
|
|
18
|
+
* and this failure then disables all imports (see first fix: https://github.com/DataDog/dd-sdk-reactnative/pull/310).
|
|
19
|
+
* However, metro does not support inline requires (see https://github.com/DataDog/dd-sdk-reactnative/issues/353), so
|
|
20
|
+
* we replace the import in this postinstall script.
|
|
21
|
+
*
|
|
22
|
+
* We choose to have 'react/jsx-runtime' as default in the code, that way we don't have to deal with this change in the source when we work on it.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
// We can only use requires in node
|
|
26
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
27
|
+
const { readFileSync, writeFileSync } = require('fs');
|
|
28
|
+
|
|
29
|
+
process.stdout.write('[datadog] postinstall replace-react-require starts\n');
|
|
30
|
+
|
|
31
|
+
const GET_JSX_RUNTIME_RELATIVE_PATH = 'rum/instrumentation/getJsxRuntime';
|
|
32
|
+
|
|
33
|
+
const isJsxExportedInReactVersion = (major, minor) => {
|
|
34
|
+
if (Number(major) > 16) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
if (Number(major) === 16 && Number(minor) > 13) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const replaceReactJsxRequire = () => {
|
|
44
|
+
process.stdout.write('[datadog] replacing react/jsx-runtime by react\n');
|
|
45
|
+
const datadogPath = `${__dirname}/..`;
|
|
46
|
+
const locations = [
|
|
47
|
+
{ directory: `${datadogPath}/src`, extension: 'ts' },
|
|
48
|
+
{ directory: `${datadogPath}/lib/commonjs`, extension: 'js' },
|
|
49
|
+
{ directory: `${datadogPath}/lib/commonjs`, extension: 'js.map' },
|
|
50
|
+
{ directory: `${datadogPath}/lib/module`, extension: 'js' },
|
|
51
|
+
{ directory: `${datadogPath}/lib/module`, extension: 'js.map' }
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
locations.forEach(location => {
|
|
55
|
+
const fileLocation = `${location.directory}/${GET_JSX_RUNTIME_RELATIVE_PATH}.${location.extension}`;
|
|
56
|
+
const file = readFileSync(fileLocation).toString();
|
|
57
|
+
writeFileSync(
|
|
58
|
+
fileLocation,
|
|
59
|
+
file.replace("require('react/jsx-runtime')", "require('react')")
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
// Get React version
|
|
66
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
67
|
+
const [major, minor] = require('react/package.json').version.split('.');
|
|
68
|
+
process.stdout.write(`[datadog] found react version ${major}${minor}\n`);
|
|
69
|
+
|
|
70
|
+
if (!isJsxExportedInReactVersion(major, minor)) {
|
|
71
|
+
replaceReactJsxRequire();
|
|
72
|
+
}
|
|
73
|
+
process.stdout.write('[datadog] postinstall replace-react-require end\n');
|
|
74
|
+
} catch (error) {
|
|
75
|
+
process.stderr.write(
|
|
76
|
+
`[datadog] Error running replace-react-require: ${error}\n`
|
|
77
|
+
);
|
|
78
|
+
}
|
|
@@ -13,6 +13,7 @@ import { DdEventsInterceptor } from './DdEventsInterceptor';
|
|
|
13
13
|
import type EventsInterceptor from './EventsInterceptor';
|
|
14
14
|
import NoOpEventsInterceptor from './NoOpEventsInterceptor';
|
|
15
15
|
import { areObjectShallowEqual } from './ShallowObjectEqualityChecker';
|
|
16
|
+
import { getJsxRuntime } from './getJsxRuntime';
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* Provides RUM auto-instrumentation feature to track user interaction as RUM events.
|
|
@@ -71,15 +72,8 @@ export class DdRumUserInteractionTracking {
|
|
|
71
72
|
};
|
|
72
73
|
|
|
73
74
|
try {
|
|
74
|
-
|
|
75
|
-
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
76
|
-
const jsxRuntime = require('react/jsx-runtime');
|
|
75
|
+
const jsxRuntime = getJsxRuntime();
|
|
77
76
|
const originaljsx = jsxRuntime.jsx;
|
|
78
|
-
if (!originaljsx) {
|
|
79
|
-
throw new Error(
|
|
80
|
-
'React version does not support new jsx transform'
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
77
|
jsxRuntime.jsx = (
|
|
84
78
|
...args: Parameters<typeof React.createElement>
|
|
85
79
|
): ReturnType<typeof React.createElement> => {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export const getJsxRuntime = () => {
|
|
8
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
9
|
+
const [major, minor] = require('react/package.json').version.split('.');
|
|
10
|
+
// We need to check on the version of React before requiring 'react/jsx-runtime') as
|
|
11
|
+
// it might crash other exports if the export does not exist (even if there is a try/catch).
|
|
12
|
+
// See: https://github.com/facebook/metro/issues/836
|
|
13
|
+
if (!isJsxExportedInReactVersion(major, minor)) {
|
|
14
|
+
throw new Error('React version does not support new jsx transform');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// /!\/!\/!\/!\/!\/!\
|
|
18
|
+
// We have to use inline require here because older React versions (below 16.14) don't have jsx-runtime.
|
|
19
|
+
// metro does not support dynamic require, so 'react/jsx-runtime' is replaced by 'react' on postinstall
|
|
20
|
+
// when react is equal or above 16.14 to avoid this require call to fail during the import phase and then
|
|
21
|
+
// disable all further imports.
|
|
22
|
+
// /!\/!\/!\/!\/!\/!\
|
|
23
|
+
//
|
|
24
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
25
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
26
|
+
if (!jsxRuntime.jsx) {
|
|
27
|
+
throw new Error('React version does not support new jsx transform');
|
|
28
|
+
}
|
|
29
|
+
return jsxRuntime;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* JSX Transform is available for React 16.14.0 (last React 16 version) and above
|
|
34
|
+
*/
|
|
35
|
+
const isJsxExportedInReactVersion = (major: string, minor: string): boolean => {
|
|
36
|
+
if (Number(major) > 16) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
if (Number(major) === 16 && Number(minor) > 13) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
};
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// generated by genversion
|
|
2
|
-
export const version = '1.1.
|
|
2
|
+
export const version = '1.1.5';
|