Skip to content

fix(ember): Guard routerService.recognize() against unrecognizable URLs - #24120

Open
aklkv wants to merge 1 commit into
getsentry:developfrom
aklkv:fix/ember-guard-router-recognize
Open

fix(ember): Guard routerService.recognize() against unrecognizable URLs#24120
aklkv wants to merge 1 commit into
getsentry:developfrom
aklkv:fix/ember-guard-router-recognize

Conversation

@aklkv

@aklkv aklkv commented Sep 6, 2026

Copy link
Copy Markdown
  • If you've added code that should be tested, please add tests.
  • Ensure your code lints and the test suite passes (yarn lint) & (yarn test).
  • Link an issue if there is one related to your pull request. If no issue is linked, one will be auto-generated and linked.

instrumentEmberAppInstanceForPerformance calls routerService.recognize(url) at three sites without guarding it.

recognize() throws for URLs the router cannot resolve. Most notably it asserts:

Assertion Failed: You must pass a url that begins with the application's rootURL "/"

whenever the URL is not prefixed with the app's rootURL — which is the case under Ember's none location, the one @ember/test-helpers installs. Since the first call happens inside browserTracingIntegration's afterAllSetup, the assertion propagates out of integration setup and takes down every acceptance test that boots the app.

Reproducing it needs nothing exotic — an app that calls instrumentAppInstancePerformance(appInstance) and has any acceptance test using visit() will hit it. Host apps currently have to work around it by skipping instrumentation under test entirely, which also costs them tracing coverage in tests.

The fix

All three call sites are already written for a missing routeInfo:

name: routeInfo ? `route:${routeInfo.name}` : /* …URL fallback… */   // pageload span
_getRouteUrlAttributes(client, url, routeInfo?.params)               // routeWillChange
routeInfo?.params ?? transition.to?.params                           // routeDidChange

The only thing missing is that recognize() throws instead of returning undefined. This routes the three sites through a small _recognizeURL() helper that catches and degrades to undefined, matching the intent the surrounding code already expresses. No intended behavior changes — a URL the router can resolve behaves exactly as before.

Notes

  • Follows the existing _getLocationURL convention in this module (// Only exported for testing).
  • Return type is derived as ReturnType<RouterService['recognize']> | undefined, so no new imports.
  • Tests are appended to tests/instrument-router-location.test.ts, which already covers this module: recognized URL passes through, the rootURL assertion yields undefined, and any other throw yields undefined.
  • Happy to add a DEBUG_BUILD-gated debug log in the catch if you'd prefer the failure be visible rather than silent — left it out to keep the change minimal.

Affects the v2 addon introduced in #23252; still present on develop and in 11.0.0-beta.1.

…URLs

`instrumentEmberAppInstanceForPerformance` calls `routerService.recognize(url)`
at three sites without guarding it. `recognize()` throws for URLs the router
cannot resolve — most notably it asserts "You must pass a url that begins with
the application's rootURL" whenever the URL is not prefixed with the app's
`rootURL`, which is the case under Ember's `none` location used by
`@ember/test-helpers`.

The first call happens inside `browserTracingIntegration`'s `afterAllSetup`, so
the assertion propagates out of integration setup and breaks every acceptance
test that boots the app.

All three call sites already treat a missing `routeInfo` as a fall back to the
URL, so route them through a small `_recognizeURL()` helper that catches and
returns `undefined`. No intended behavior changes.
@aklkv
aklkv requested a review from a team as a code owner September 6, 2026 02:16
@aklkv
aklkv requested review from mydea and s1gr1d and removed request for a team September 6, 2026 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant