{"version":3,"file":"withEmbraceRoutingLegacy.cjs","names":["React"],"sources":["../../../../../../src/instrumentations/navigation/NavigationInstrumentation/react/reactRouterV5/withEmbraceRoutingLegacy.ts"],"sourcesContent":["import hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\nimport { page } from '../../../../../api-page/index.ts';\nimport type {\n  RouteComponentProps,\n  SwitchedRouteComponentProps,\n} from './types.ts';\n\nexport const withEmbraceRoutingLegacy = <P extends RouteComponentProps>(\n  WrappedComponent: React.ComponentType<P>,\n) => {\n  const RouteWithEmbraceRoutingLegacy: React.FC<P> = (props: P) => {\n    // Make sure this is Route component\n    if (props.path) {\n      // Routes get injected with computedMatch when they are children of a <Switch> but the types do not reflect that\n      // Manually setting the type here.\n      const routeProps = props as SwitchedRouteComponentProps;\n\n      // Depends on this internal behaviour\n      // https://github.com/remix-run/react-router/blob/v5.3.4/packages/react-router/modules/Switch.js#L40\n      // It shouldn't change as this version is legacy, and it's not being actively worked on\n      if (routeProps.computedMatch) {\n        page.setCurrentRoute({\n          path: routeProps.computedMatch.path,\n          url: routeProps.computedMatch.url,\n        });\n      }\n    }\n\n    return React.createElement<P>(WrappedComponent, props);\n  };\n\n  // Keep wrapped component metadata\n  RouteWithEmbraceRoutingLegacy.displayName = `withEmbraceRoutingLegacy(${WrappedComponent.displayName || WrappedComponent.name || 'Component'})`;\n  hoistNonReactStatics(RouteWithEmbraceRoutingLegacy, WrappedComponent);\n\n  return RouteWithEmbraceRoutingLegacy;\n};\n"],"mappings":";;;;;;;;AAQA,MAAa,4BACX,qBACG;CACH,MAAM,iCAA8C,UAAa;EAE/D,IAAI,MAAM,MAAM;GAGd,MAAM,aAAa;GAKnB,IAAI,WAAW,eACb,yBAAA,KAAK,gBAAgB;IACnB,MAAM,WAAW,cAAc;IAC/B,KAAK,WAAW,cAAc;GAChC,CAAC;EAEL;EAEA,OAAOA,MAAM,cAAiB,kBAAkB,KAAK;CACvD;CAGA,8BAA8B,cAAc,4BAA4B,iBAAiB,eAAe,iBAAiB,QAAQ,YAAY;CAC7I,CAAA,GAAA,wBAAA,QAAA,CAAqB,+BAA+B,gBAAgB;CAEpE,OAAO;AACT"}