{"action":"created","issue":{"url":"https://api.github.com/repos/ngrx/effects/issues/123","repository_url":"https://api.github.com/repos/ngrx/effects","labels_url":"https://api.github.com/repos/ngrx/effects/issues/123/labels{/name}","comments_url":"https://api.github.com/repos/ngrx/effects/issues/123/comments","events_url":"https://api.github.com/repos/ngrx/effects/issues/123/events","html_url":"https://github.com/ngrx/effects/issues/123","id":217601215,"number":123,"title":"Effects imported by multiple lazy loaded modules loaded multiple times","user":{"login":"karptonite","id":132278,"avatar_url":"https://avatars1.githubusercontent.com/u/132278?v=4","gravatar_id":"","url":"https://api.github.com/users/karptonite","html_url":"https://github.com/karptonite","followers_url":"https://api.github.com/users/karptonite/followers","following_url":"https://api.github.com/users/karptonite/following{/other_user}","gists_url":"https://api.github.com/users/karptonite/gists{/gist_id}","starred_url":"https://api.github.com/users/karptonite/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/karptonite/subscriptions","organizations_url":"https://api.github.com/users/karptonite/orgs","repos_url":"https://api.github.com/users/karptonite/repos","events_url":"https://api.github.com/users/karptonite/events{/privacy}","received_events_url":"https://api.github.com/users/karptonite/received_events","type":"User","site_admin":false},"labels":[{"id":601763216,"url":"https://api.github.com/repos/ngrx/effects/labels/Fixed%20in%204.0","name":"Fixed in 4.0","color":"0e8a16","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2017-03-28T15:33:54Z","updated_at":"2017-07-19T03:24:46Z","closed_at":"2017-07-19T03:24:46Z","body":"Now that the https://github.com/angular/angular/issues/12869 is fixed, providers no longer always instantiate twice with lazy loading.\r\n\r\nHowever, there is another related issue that still exists, I believe. If you have an effect that is used by more than one lazy loaded endpoint, it will be loaded multiple times if you go from route to route between them. \r\n\r\nFor example, we have a tagging system, which has its own nxrx/effects. The tags are used by the images, the files, and the videos systems (each lazy loaded). \r\n\r\nIdeally, the tagging effects (with dependencies) would only be loaded for these particular pages. However, if they are loaded in the `imports` section of each lazy-loaded module, they are instantiated each time the user uses a `routerLink` to jump from one type to another. That means that the effects are dispatched more than once if the user has visited different sorts of pages.\r\n\r\nOf course, we could solve this by importing any effects that are needed for multiple lazy loaded modules in the root app module, or in some module imported by the app module. But that is obviously not ideal from a lazy loading perspective, since we don't need tags on all pages, just a small subset of them. \r\n\r\nI'm not sure of the best solution for this--here are a couple of naive suggestions, though. One option, though, would be to change EffectsModule.run so that it skips Effects classes that have been previously imported. Another option would be to somehow limit the effects that run on a lazy-loaded route to those that were imported and run by the lazy loaded module or the AppModule. That would mean that if a user starts on a file page, and imports the Tag effects, then switches to the image page, the image page module would also import its own instance of the Tag effects, but the Tag effects previously imported in \"files\" would be inactive. \r\n\r\nI don't know enough about Angular internals or how ngrx/effects works to know if either of these are workable solutions."},"comment":{"url":"https://api.github.com/repos/ngrx/effects/issues/comments/316261911","html_url":"https://github.com/ngrx/effects/issues/123#issuecomment-316261911","issue_url":"https://api.github.com/repos/ngrx/effects/issues/123","id":316261911,"user":{"login":"robwormald","id":534930,"avatar_url":"https://avatars1.githubusercontent.com/u/534930?v=4","gravatar_id":"","url":"https://api.github.com/users/robwormald","html_url":"https://github.com/robwormald","followers_url":"https://api.github.com/users/robwormald/followers","following_url":"https://api.github.com/users/robwormald/following{/other_user}","gists_url":"https://api.github.com/users/robwormald/gists{/gist_id}","starred_url":"https://api.github.com/users/robwormald/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robwormald/subscriptions","organizations_url":"https://api.github.com/users/robwormald/orgs","repos_url":"https://api.github.com/users/robwormald/repos","events_url":"https://api.github.com/users/robwormald/events{/privacy}","received_events_url":"https://api.github.com/users/robwormald/received_events","type":"User","site_admin":false},"created_at":"2017-07-19T03:24:46Z","updated_at":"2017-07-19T03:24:46Z","body":"Please check this against NgRx v4, and if it’s still an issue, please reopen on https://github.com/ngrx/platform. Thanks!"}}
{"actor":{"display_login":"robwormald"}}