@datadog/mobile-react-native 1.1.3 → 1.1.4
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 +55 -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 +45 -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 +2 -2
- 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;;AAIA;AACH;;AACDN,IAAAA,4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C,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,55 @@
|
|
|
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 calling require('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
|
+
} // React Native does some premature optimizations if the require target is a static string, by making
|
|
23
|
+
// it dynamic we prevent RN from trying to resolve react/jsx-runtime before the function is called
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
const jsxRuntimePackage = isJsxExportedInReactVersion(major, minor) ? 'react/jsx-runtime' : 'react'; // We have to use inline require here because older React versions (below 17) don't have jsx-runtime
|
|
27
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires, import/no-dynamic-require
|
|
28
|
+
|
|
29
|
+
const jsxRuntime = require(jsxRuntimePackage);
|
|
30
|
+
|
|
31
|
+
if (!jsxRuntime.jsx) {
|
|
32
|
+
throw new Error('React version does not support new jsx transform');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return jsxRuntime.jsx;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* JSX Transform is available for React 16.14.0 (last React 16 version) and above
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
exports.getJsxRuntime = getJsxRuntime;
|
|
43
|
+
|
|
44
|
+
const isJsxExportedInReactVersion = (major, minor) => {
|
|
45
|
+
if (Number(major) > 16) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (Number(major) === 16 && Number(minor) > 13) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return false;
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=getJsxRuntime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["getJsxRuntime.ts"],"names":["getJsxRuntime","major","minor","require","version","split","isJsxExportedInReactVersion","Error","jsxRuntimePackage","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,QAAMC,iBAAiB,GAAGF,2BAA2B,CAACL,KAAD,EAAQC,KAAR,CAA3B,GACpB,mBADoB,GAEpB,OAFN,CAZ+B,CAgB/B;AACA;;AACA,QAAMO,UAAU,GAAGN,OAAO,CAACK,iBAAD,CAA1B;;AACA,MAAI,CAACC,UAAU,CAACC,GAAhB,EAAqB;AACjB,UAAM,IAAIH,KAAJ,CAAU,kDAAV,CAAN;AACH;;AACD,SAAOE,UAAU,CAACC,GAAlB;AACH,CAvBM;AAyBP;AACA;AACA;;;;;AACA,MAAMJ,2BAA2B,GAAG,CAACL,KAAD,EAAgBC,KAAhB,KAA2C;AAC3E,MAAIS,MAAM,CAACV,KAAD,CAAN,GAAgB,EAApB,EAAwB;AACpB,WAAO,IAAP;AACH;;AACD,MAAIU,MAAM,CAACV,KAAD,CAAN,KAAkB,EAAlB,IAAwBU,MAAM,CAACT,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 calling require('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 // React Native does some premature optimizations if the require target is a static string, by making\n // it dynamic we prevent RN from trying to resolve react/jsx-runtime before the function is called\n const jsxRuntimePackage = isJsxExportedInReactVersion(major, minor)\n ? 'react/jsx-runtime'\n : 'react';\n\n // We have to use inline require here because older React versions (below 17) don't have jsx-runtime\n // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires, import/no-dynamic-require\n const jsxRuntime = require(jsxRuntimePackage);\n if (!jsxRuntime.jsx) {\n throw new Error('React version does not support new jsx transform');\n }\n return jsxRuntime.jsx;\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.4';\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,S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AIH;;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,45 @@
|
|
|
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 calling require('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
|
+
} // React Native does some premature optimizations if the require target is a static string, by making
|
|
16
|
+
// it dynamic we prevent RN from trying to resolve react/jsx-runtime before the function is called
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
const jsxRuntimePackage = isJsxExportedInReactVersion(major, minor) ? 'react/jsx-runtime' : 'react'; // We have to use inline require here because older React versions (below 17) don't have jsx-runtime
|
|
20
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires, import/no-dynamic-require
|
|
21
|
+
|
|
22
|
+
const jsxRuntime = require(jsxRuntimePackage);
|
|
23
|
+
|
|
24
|
+
if (!jsxRuntime.jsx) {
|
|
25
|
+
throw new Error('React version does not support new jsx transform');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return jsxRuntime.jsx;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* JSX Transform is available for React 16.14.0 (last React 16 version) and above
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
const isJsxExportedInReactVersion = (major, minor) => {
|
|
35
|
+
if (Number(major) > 16) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (Number(major) === 16 && Number(minor) > 13) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return false;
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=getJsxRuntime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["getJsxRuntime.ts"],"names":["getJsxRuntime","major","minor","require","version","split","isJsxExportedInReactVersion","Error","jsxRuntimePackage","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,QAAMC,iBAAiB,GAAGF,2BAA2B,CAACL,KAAD,EAAQC,KAAR,CAA3B,GACpB,mBADoB,GAEpB,OAFN,CAZ+B,CAgB/B;AACA;;AACA,QAAMO,UAAU,GAAGN,OAAO,CAACK,iBAAD,CAA1B;;AACA,MAAI,CAACC,UAAU,CAACC,GAAhB,EAAqB;AACjB,UAAM,IAAIH,KAAJ,CAAU,kDAAV,CAAN;AACH;;AACD,SAAOE,UAAU,CAACC,GAAlB;AACH,CAvBM;AAyBP;AACA;AACA;;AACA,MAAMJ,2BAA2B,GAAG,CAACL,KAAD,EAAgBC,KAAhB,KAA2C;AAC3E,MAAIS,MAAM,CAACV,KAAD,CAAN,GAAgB,EAApB,EAAwB;AACpB,WAAO,IAAP;AACH;;AACD,MAAIU,MAAM,CAACV,KAAD,CAAN,KAAkB,EAAlB,IAAwBU,MAAM,CAACT,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 calling require('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 // React Native does some premature optimizations if the require target is a static string, by making\n // it dynamic we prevent RN from trying to resolve react/jsx-runtime before the function is called\n const jsxRuntimePackage = isJsxExportedInReactVersion(major, minor)\n ? 'react/jsx-runtime'\n : 'react';\n\n // We have to use inline require here because older React versions (below 17) don't have jsx-runtime\n // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires, import/no-dynamic-require\n const jsxRuntime = require(jsxRuntimePackage);\n if (!jsxRuntime.jsx) {\n throw new Error('React version does not support new jsx transform');\n }\n return jsxRuntime.jsx;\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.4';\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.4";
|
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.4",
|
|
4
4
|
"description": "A client-side React Native module to interact with Datadog",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"datadog",
|
|
@@ -73,5 +73,5 @@
|
|
|
73
73
|
]
|
|
74
74
|
]
|
|
75
75
|
},
|
|
76
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "7baf5db95c89544dde5488437b43f13cccb3a18e"
|
|
77
77
|
}
|
|
@@ -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 calling require('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
|
+
// React Native does some premature optimizations if the require target is a static string, by making
|
|
18
|
+
// it dynamic we prevent RN from trying to resolve react/jsx-runtime before the function is called
|
|
19
|
+
const jsxRuntimePackage = isJsxExportedInReactVersion(major, minor)
|
|
20
|
+
? 'react/jsx-runtime'
|
|
21
|
+
: 'react';
|
|
22
|
+
|
|
23
|
+
// We have to use inline require here because older React versions (below 17) don't have jsx-runtime
|
|
24
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires, import/no-dynamic-require
|
|
25
|
+
const jsxRuntime = require(jsxRuntimePackage);
|
|
26
|
+
if (!jsxRuntime.jsx) {
|
|
27
|
+
throw new Error('React version does not support new jsx transform');
|
|
28
|
+
}
|
|
29
|
+
return jsxRuntime.jsx;
|
|
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.4';
|