Files
discord-decomp/_bundle/Module1168.js
T
2026-11-01 12:12:55 +02:00

298 lines
12 KiB
JavaScript

// Metro module 1168 (f1169).
import * as _startIdleSpan from "./startIdleSpan";
import { getDefaultIdleNavigationSpanOptions, DEFAULT_NAVIGATION_SPAN_NAME } from "./startIdleSpan";
import { NATIVE } from "./Module1001";
import { debug, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, getClient, startInactiveSpan, spanToJSON, timestampInSeconds, SPAN_STATUS_OK, SEMANTIC_ATTRIBUTE_SENTRY_OP, addBreadcrumb, isPlainObject } from "./Module817";
import { getReactNativeTracingIntegration } from "./Module1166";
import { getAppRegistryIntegration } from "./patchAppRegistryRunApplication";
import { RN_GLOBAL_OBJ } from "./Module816";
import { SPAN_ORIGIN_AUTO_NAVIGATION_REACT_NAVIGATION } from "./Module1158";
import { SEMANTIC_ATTRIBUTE_NAVIGATION_ACTION_TYPE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from "./Module1157";
import { ignoreEmptyBackNavigation, ignoreEmptyRouteChangeTransactions } from "./Module1161";
import { addTimeToInitialDisplayFallback } from "./Module1169";
import { isSentrySpan } from "./Module1122";
const name = "ReactNavigation";
export const INTEGRATION_NAME = "ReactNavigation";
export const reactNavigationIntegration = function(r3 = {}) {
let routeChangeTimeoutMs = r3.routeChangeTimeoutMs;
if (routeChangeTimeoutMs === void 0) {
routeChangeTimeoutMs = 1000;
}
let current, reactNativeTracingIntegration, currentRoute, c12875_8, c12875_9, c12875_10, startIdleNavigationSpan2, updateLatestNavigationSpanWithCurrentRoute2, pushRecentRouteKey2, _discardLatestTransaction2, clearStateChangeTimeout2;
let c12875_0 = routeChangeTimeoutMs;
let enableTimeToInitialDisplay = r3.enableTimeToInitialDisplay;
if (enableTimeToInitialDisplay === void 0) {
enableTimeToInitialDisplay = false;
}
let c12875_1 = enableTimeToInitialDisplay;
let ignoreEmptyBackNavigationTransactions = r3.ignoreEmptyBackNavigationTransactions;
if (ignoreEmptyBackNavigationTransactions === void 0) {
ignoreEmptyBackNavigationTransactions = true;
}
let c12875_2 = ignoreEmptyBackNavigationTransactions;
const { enableTimeToInitialDisplayForPreloadedRoutes = false, useDispatchedActionData = false } = r3;
let c12875_3 = useDispatchedActionData;
let useFullPathsForNavigationRoutes = r3.useFullPathsForNavigationRoutes;
if (useFullPathsForNavigationRoutes === void 0) {
useFullPathsForNavigationRoutes = false;
}
let c12875_4 = useFullPathsForNavigationRoutes;
current = void 0;
reactNativeTracingIntegration = void 0;
currentRoute = void 0;
c12875_8 = void 0;
c12875_9 = void 0;
c12875_10 = void 0;
startIdleNavigationSpan2 = void 0;
updateLatestNavigationSpanWithCurrentRoute2 = void 0;
pushRecentRouteKey2 = void 0;
_discardLatestTransaction2 = void 0;
clearStateChangeTimeout2 = void 0;
let defaultIdleOptions = _startIdleSpan.defaultIdleOptions;
let c12875_12 = false;
let c12875_13 = [];
if (enableTimeToInitialDisplay) {
NATIVE.initNativeReactNavigationNewFrameTracking().catch((error) => {
debug.error(`${name} Failed to initialize native new frame tracking: ${error}`);
});
}
startIdleNavigationSpan2 = function startIdleNavigationSpan(a0, isAppRestart = false) {
let c24269_0;
c24269_0 = void 0;
if (c12875_3 && (a0 == null ? void 0 : a0.data.noop)) {
debug.log(`${name} Navigation action is a noop, not starting navigation span.`);
} else {
const r10 = c12875_3 ? a0 == null ? void 0 : a0.data.action.type : void 0;
if (c12875_3 && (r10 && ["PRELOAD", "SET_PARAMS", "OPEN_DRAWER", "CLOSE_DRAWER", "TOGGLE_DRAWER"].includes(r10))) {
debug.log(`${name} Navigation action is ${r10}, not starting navigation span.`);
} else {
if (c12875_8) {
debug.log(`${name} A transaction was detected that turned out to be a noop, discarding.`);
if (c12875_8) {
if (isSentrySpan(c12875_8)) {
c12875_8._sampled = false;
}
c12875_8.end();
c12875_8 = void 0;
}
if (c12875_9) {
c12875_9 = void 0;
}
if (c12875_10 !== void 0) {
clearTimeout(c12875_10);
c12875_10 = void 0;
}
}
const r100 = _startIdleSpan.startIdleNavigationSpan((reactNativeTracingIntegration == null ? void 0 : reactNativeTracingIntegration.options.beforeStartSpan) ? reactNativeTracingIntegration.options.beforeStartSpan(getDefaultIdleNavigationSpanOptions()) : getDefaultIdleNavigationSpanOptions(), {
...defaultIdleOptions,
isAppRestart
});
c12875_8 = r100;
if (r100 != null) {
c12875_8.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SPAN_ORIGIN_AUTO_NAVIGATION_REACT_NAVIGATION);
}
if (c12875_8 != null) {
c12875_8.setAttribute(SEMANTIC_ATTRIBUTE_NAVIGATION_ACTION_TYPE, r10);
}
if (c12875_2) {
ignoreEmptyBackNavigation(getClient(), c12875_8);
}
const r137 = c12875_8;
c24269_0 = r137;
ignoreEmptyRouteChangeTransactions(getClient(), r137, DEFAULT_NAVIGATION_SPAN_NAME, () => c12875_8 === c24269_0);
if (c12875_1 && c12875_8) {
NATIVE.setActiveSpanId(c12875_8.spanContext().spanId);
const r181 = startInactiveSpan({
op: "navigation.processing",
name: "Navigation dispatch to navigation cancelled or screen mounted",
startTime: spanToJSON(c12875_8).start_timestamp
});
c12875_9 = r181;
r181.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SPAN_ORIGIN_AUTO_NAVIGATION_REACT_NAVIGATION);
}
c12875_10 = setTimeout(_discardLatestTransaction2, c12875_0);
}
}
};
updateLatestNavigationSpanWithCurrentRoute2 = () => {
const r12 = timestampInSeconds();
const r15 = currentRoute;
if (current) {
const currentRoute2 = current.getCurrentRoute();
if (currentRoute2) {
if (c12875_8) {
addTimeToInitialDisplayFallback(c12875_8.spanContext().spanId, NATIVE.getNewScreenTimeToDisplay());
if (r15 && r15.key === currentRoute2.key) {
debug.log(`[${name}] Navigation state changed, but route is the same as previous.`);
c12875_13.push(currentRoute2.key);
if (c12875_13.length > 200) {
c12875_13 = c12875_13.slice(c12875_13.length - 200);
}
currentRoute = currentRoute2;
c12875_8 = void 0;
return void 0;
}
const r17 = c12875_13.includes(currentRoute2.key);
let name2 = currentRoute2.name;
if (c12875_4) {
let r80 = current.getState();
let r81 = void 0;
if (r80) {
const r18 = [];
while (r80) {
const index = r80.index;
const r85 = r80.routes[index !== null ? index !== void 0 ? index : 0 : 0];
if (r85?.name) {
r18.push(r85.name);
}
r80 = r85?.state;
}
r81 = r18.length > 0 ? r18.join("/") : void 0;
}
if (!r81) {
r81 = currentRoute2.name;
}
name2 = r81;
}
if (c12875_9 != null) {
c12875_9.updateName(`Navigation dispatch to screen ${name2} mounted`);
}
if (c12875_9 != null) {
c12875_9.setStatus({
code: SPAN_STATUS_OK
});
}
if (c12875_9 != null) {
c12875_9.end(r12);
}
c12875_9 = void 0;
if (spanToJSON(c12875_8).description === DEFAULT_NAVIGATION_SPAN_NAME) {
c12875_8.updateName(name2);
}
const r136 = c12875_8;
const r139 = {
"route.name": name2,
"route.key": currentRoute2.key,
"route.has_been_seen": r17,
"previous_route.name": r15?.name,
"previous_route.key": r15?.key
};
r139[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] = "component";
r139[SEMANTIC_ATTRIBUTE_SENTRY_OP] = "navigation";
r136.setAttributes(r139);
if (c12875_10 !== void 0) {
clearTimeout(c12875_10);
c12875_10 = void 0;
}
addBreadcrumb({
category: "navigation",
type: "navigation",
message: `Navigation to ${name2}`,
data: {
from: r15?.name,
to: name2
}
});
if (reactNativeTracingIntegration != null) {
reactNativeTracingIntegration.setCurrentRoute(name2);
}
c12875_13.push(currentRoute2.key);
if (c12875_13.length > 200) {
c12875_13 = c12875_13.slice(c12875_13.length - 200);
}
currentRoute = c12875_4 ? {
...currentRoute2,
name: name2
} : currentRoute2;
c12875_8 = void 0;
} else {
debug.log(`[${name}] Navigation state changed, but navigation transaction was not started on dispatch.`);
}
} else {
debug.log(`[${name}] Navigation state changed, but no route is rendered.`);
}
} else {
debug.warn(`${name} Missing navigation container ref. Route transactions will not be sent.`);
}
};
pushRecentRouteKey2 = (a0) => {};
_discardLatestTransaction2 = () => {
if (c12875_8) {
if (isSentrySpan(c12875_8)) {
c12875_8._sampled = false;
}
c12875_8.end();
c12875_8 = void 0;
}
if (c12875_9) {
c12875_9 = void 0;
}
};
clearStateChangeTimeout2 = () => {};
return {
name,
afterAllSetup: (a0) => {
reactNativeTracingIntegration = getReactNativeTracingIntegration(a0);
if (reactNativeTracingIntegration) {
defaultIdleOptions = {
finalTimeout: reactNativeTracingIntegration.options.finalTimeoutMs,
idleTimeout: reactNativeTracingIntegration.options.idleTimeoutMs
};
}
if (!c12875_12) {
const appRegistryIntegration = getAppRegistryIntegration(a0);
if (!(appRegistryIntegration === null || appRegistryIntegration === void 0)) {
appRegistryIntegration.onRunApplication(() => {
if (c12875_12) {
debug.log("[ReactNavigationIntegration] Starting new idle navigation span based on runApplication call.");
startIdleNavigationSpan2(void 0, true);
}
});
}
startIdleNavigationSpan2();
if (current) {
updateLatestNavigationSpanWithCurrentRoute2();
c12875_12 = true;
}
}
},
registerNavigationContainer: (a0) => {
if (RN_GLOBAL_OBJ.__sentry_rn_v5_registered) {
debug.log(`${name} Instrumentation already exists, but registering again...`);
}
const r29 = isPlainObject(a0) ? "current" in a0 ? a0.current : a0 : a0;
if (current !== r29) {
current = r29;
if (current) {
current.addListener("__unsafe_action__", startIdleNavigationSpan2);
current.addListener("state", updateLatestNavigationSpanWithCurrentRoute2);
RN_GLOBAL_OBJ.__sentry_rn_v5_registered = true;
if (!c12875_12) {
if (c12875_8) {
updateLatestNavigationSpanWithCurrentRoute2();
c12875_12 = true;
} else {
debug.log(`${name} Navigation container registered, but integration has not been setup yet.`);
}
}
} else {
debug.warn(`${name} Received invalid navigation container ref!`);
}
} else {
debug.log(`${name} Navigation container ref is the same as the one already registered.`);
}
},
options: {
routeChangeTimeoutMs,
enableTimeToInitialDisplay,
ignoreEmptyBackNavigationTransactions,
enableTimeToInitialDisplayForPreloadedRoutes,
useDispatchedActionData,
useFullPathsForNavigationRoutes
}
};
};
export function getReactNavigationIntegration(a0) {
return a0.getIntegrationByName(name);
}