fix(ember): Guard routerService.recognize() against unrecognizable URLs - #24120
Open
aklkv wants to merge 1 commit into
Open
fix(ember): Guard routerService.recognize() against unrecognizable URLs#24120aklkv wants to merge 1 commit into
routerService.recognize() against unrecognizable URLs#24120aklkv wants to merge 1 commit into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
yarn lint) & (yarn test).instrumentEmberAppInstanceForPerformancecallsrouterService.recognize(url)at three sites without guarding it.recognize()throws for URLs the router cannot resolve. Most notably it asserts:whenever the URL is not prefixed with the app's
rootURL— which is the case under Ember'snonelocation, the one@ember/test-helpersinstalls. Since the first call happens insidebrowserTracingIntegration'safterAllSetup, 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 usingvisit()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:The only thing missing is that
recognize()throws instead of returningundefined. This routes the three sites through a small_recognizeURL()helper that catches and degrades toundefined, matching the intent the surrounding code already expresses. No intended behavior changes — a URL the router can resolve behaves exactly as before.Notes
_getLocationURLconvention in this module (// Only exported for testing).ReturnType<RouterService['recognize']> | undefined, so no new imports.tests/instrument-router-location.test.ts, which already covers this module: recognized URL passes through, therootURLassertion yieldsundefined, and any other throw yieldsundefined.DEBUG_BUILD-gated debug log in thecatchif 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
developand in11.0.0-beta.1.