Router.map callbacks hung off Router constructor
- Dominant language
- TypeScript
- Stars
- 22.6k
- Forks
- 4.2k
- Avg merge
- 3d 12h
- Merged PRs (30d)
- 15
Description
`Router.map` hangs the callback functions it receives within `Router.constructor.dslCallbacks`. In a traditional client-side rendered Ember-world, this is harmless.
However, when you take into account FastBoot, this becomes unsafe if you call `Router.map` multiple times within your application those functions can leak across instances. A particular use-case is we registered routes dynamically depending on user state and we do this inside of an instance-initializer.
This isn't a terribly uncommon pattern; example is someone who wants to register routes in the language of the user. This is likely the place where that would happen.
Where this becomes a problem in FastBoot is each time a request is made the callback is pushed to a property on the constructor and then enumerated over and invoked. So for each request, a new callback is pushed into the array of callbacks and no clean up takes place (a memory leak and unsafe where functions from previous app instances are invoked).
https://github.com/emberjs/ember.js/blob/master/packages/ember-routing/lib/system/router.js#L89-L96
Are the lines in question and so I was wondering if anyone would be opened to me moving these callbacks elsewhere, such as the application instance. This will have larger ramifications, so would like to gather interest or feedback first.
Contributor guide
Assessment
This issue has not been assessed yet.