Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(link-manager): Use private router API to query currentURL in a side-effect-free way #518

Merged
merged 1 commit into from
Jan 29, 2021

Conversation

Turbo87
Copy link
Collaborator

@Turbo87 Turbo87 commented Jan 29, 2021

As the code comment says: as soon as you use a Link component we internally try to figure out if the router was initialized and if we do that by accessing currentURL on the public router service, this causes the router to initialize as an unintended side-effect. This can cause issues for any following LinkTo components which deal with incomplete route models, as can be seen in the provided regression test.

This PR works around the problem by accessing the currentURL property on the private router instead, inspired by the currentURL() test helper (see https://github.com/emberjs/ember-test-helpers/blob/v2.1.4/addon-test-support/@ember/test-helpers/setup-application-context.ts#L180). This does not cause the router to initialize and thus avoids the problem mentioned above.

@Turbo87 Turbo87 added the enhancement New feature or request label Jan 29, 2021
Copy link
Owner

@buschtoens buschtoens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:chef-kiss:

@buschtoens buschtoens changed the title services/link-manager: Use private router API to query currentURL in a side-effect-free way fix(link-manager): Use private router API to query currentURL in a side-effect-free way Jan 29, 2021
@buschtoens buschtoens merged commit a0278c9 into buschtoens:master Jan 29, 2021
@Turbo87 Turbo87 deleted the private-api branch November 17, 2021 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants