Skip to content

ref: remove withSentryRouter HOC#115949

Merged
evanpurkhiser merged 1 commit into
masterfrom
evanpurkhiser/ref-remove-withsentryrouter-hoc
May 20, 2026
Merged

ref: remove withSentryRouter HOC#115949
evanpurkhiser merged 1 commit into
masterfrom
evanpurkhiser/ref-remove-withsentryrouter-hoc

Conversation

@evanpurkhiser
Copy link
Copy Markdown
Member

withSentryRouter was a withRouter-style HOC that emulated the react-router 3 WithRouterProps interface (location, params, router, routes) and remapped orgId to the current customer domain. There are only five consumers, and none of them actually read params.orgId from the remap — they just want the underlying router data.

Migrate each consumer to the specific hook (or prop) it actually needs and delete the HOC:

  • jsonForm: function component. Drop the HOC, call useLocation() directly for the scroll-to-hash behaviour, and stop forwarding the legacy location/params/router/routes props to user visible callbacks — no callback in the tree consumes them.
  • dateRange: class component. Take routes: PlainRoute[] as a prop (used only for getRouteStringFromRoutes in analytics) and inject it via a thin WithRoutes function wrapper that calls useRoutes().
  • releaseSeries: class component. Take location and navigate as props. Replace router.location.query.project with location.query.project and router.push(...) with navigate(...). Inject via a WithRouter wrapper around the existing withOrganization(withApi(withTheme(...))) stack. The spec drops the synthetic router/routes/params/location fixture overrides — the hooks supply real values now.
  • releaseSessionsChart: class component that only reads location. Inject via a WithLocation wrapper.
  • widgetCard: function component. Drop the HOC entirely and call useLocation() directly alongside the existing useNavigate / useOrganization / useParams calls.

Also drop the no-restricted-imports entry for sentry/utils/withSentryRouter from eslint.config.ts and delete withSentryRouter.tsx / withSentryRouter.spec.tsx.

Follow-up to #115945 (which removed useRouter) — this finishes off the last in-repo consumer of legacy router HOCs.

See https://github.com/getsentry/frontend-tsc/issues/78

@evanpurkhiser evanpurkhiser requested a review from a team May 20, 2026 21:00
@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label May 20, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 20, 2026

📊 Type Coverage Diff

Metric Before After Delta
Coverage 93.58% 93.58% ±0%
Typed 135,603 135,601 🔴 -2
Untyped 9,309 9,298 🟢 -11
🔍 3 new type safety issues introduced

any-typed symbols (3 new)

File Line Detail
static/app/components/timeRangeSelector/dateRange.tsx 124 routes (var(binding))
static/app/components/timeRangeSelector/dateRange.tsx 153 routes (var(binding))
static/app/components/timeRangeSelector/dateRange.tsx 246 routes (var)

This is informational only and does not block the PR.

`withSentryRouter` was a `withRouter`-style HOC that emulated the
react-router 3 `WithRouterProps` interface (`location`, `params`, `router`,
`routes`) and remapped `orgId` to the current customer domain. There are
only five consumers, and none of them actually read `params.orgId` from
the remap -- they just want the underlying router data.

Migrate each consumer to the specific hook (or prop) it actually needs
and delete the HOC:

- `jsonForm`: function component. Drop the HOC, call `useLocation()`
  directly for the scroll-to-hash behaviour, and stop forwarding the
  legacy `location`/`params`/`router`/`routes` props to user `visible`
  callbacks -- no callback in the tree consumes them.
- `dateRange`: class component. Take `routes: PlainRoute[]` as a prop
  (used only for `getRouteStringFromRoutes` in analytics) and inject it
  via a thin `WithRoutes` function wrapper that calls `useRoutes()`.
- `releaseSeries`: class component. Take `location` and `navigate` as
  props. Replace `router.location.query.project` with `location.query.project`
  and `router.push(...)` with `navigate(...)`. Inject via a `WithRouter`
  wrapper around the existing `withOrganization(withApi(withTheme(...)))`
  stack. The spec drops the synthetic `router`/`routes`/`params`/`location`
  fixture overrides -- the hooks supply real values now.
- `releaseSessionsChart`: class component that only reads `location`.
  Inject via a `WithLocation` wrapper.
- `widgetCard`: function component. Drop the HOC entirely and call
  `useLocation()` directly alongside the existing `useNavigate` /
  `useOrganization` / `useParams` calls.

Also drop the `no-restricted-imports` entry for `sentry/utils/withSentryRouter`
from `eslint.config.ts` and delete `withSentryRouter.tsx` /
`withSentryRouter.spec.tsx`.

See getsentry/frontend-tsc#78
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-remove-withsentryrouter-hoc branch from a995758 to abc2f57 Compare May 20, 2026 21:14
@evanpurkhiser evanpurkhiser requested review from a team as code owners May 20, 2026 21:14
@evanpurkhiser evanpurkhiser merged commit bab5c6c into master May 20, 2026
71 checks passed
@evanpurkhiser evanpurkhiser deleted the evanpurkhiser/ref-remove-withsentryrouter-hoc branch May 20, 2026 21:22
JonasBa pushed a commit that referenced this pull request May 21, 2026
`withSentryRouter` was a `withRouter`-style HOC that emulated the
react-router 3 `WithRouterProps` interface (`location`, `params`,
`router`, `routes`) and remapped `orgId` to the current customer domain.
There are only five consumers, and none of them actually read
`params.orgId` from the remap — they just want the underlying router
data.

Migrate each consumer to the specific hook (or prop) it actually needs
and delete the HOC:

- `jsonForm`: function component. Drop the HOC, call `useLocation()`
directly for the scroll-to-hash behaviour, and stop forwarding the
legacy `location`/`params`/`router`/`routes` props to user `visible`
callbacks — no callback in the tree consumes them.
- `dateRange`: class component. Take `routes: PlainRoute[]` as a prop
(used only for `getRouteStringFromRoutes` in analytics) and inject it
via a thin `WithRoutes` function wrapper that calls `useRoutes()`.
- `releaseSeries`: class component. Take `location` and `navigate` as
props. Replace `router.location.query.project` with
`location.query.project` and `router.push(...)` with `navigate(...)`.
Inject via a `WithRouter` wrapper around the existing
`withOrganization(withApi(withTheme(...)))` stack. The spec drops the
synthetic `router`/`routes`/`params`/`location` fixture overrides — the
hooks supply real values now.
- `releaseSessionsChart`: class component that only reads `location`.
Inject via a `WithLocation` wrapper.
- `widgetCard`: function component. Drop the HOC entirely and call
`useLocation()` directly alongside the existing `useNavigate` /
`useOrganization` / `useParams` calls.

Also drop the `no-restricted-imports` entry for
`sentry/utils/withSentryRouter` from `eslint.config.ts` and delete
`withSentryRouter.tsx` / `withSentryRouter.spec.tsx`.

Follow-up to #115945 (which removed `useRouter`) — this finishes off the
last in-repo consumer of legacy router HOCs.

See getsentry/frontend-tsc#78
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants