Skip to content

fix(icon): not taking current path after initialization #13641

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

Merged
merged 1 commit into from
Oct 18, 2018

Conversation

crisbeto
Copy link
Member

When resolving the current path while prefixing url() references, we use a provider to get the current path so we can account for server-side rendering and to be able to stub it out during tests. Since the provider is an object with a regular pathname property, the path will only be resolved once the first time an icon is resolved and then it'll be cached. This means that all subsequent icons will take an incorrect path.

Related to #13628.

@crisbeto crisbeto added the target: patch This PR is targeted for the next patch release label Oct 17, 2018
@crisbeto crisbeto requested a review from jelbourn as a code owner October 17, 2018 11:01
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Oct 17, 2018
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

When resolving the current path while prefixing `url()` references, we use a provider to get the current path so we can account for server-side rendering and to be able to stub it out during tests. Since the provider is an object with a regular `pathname` property, the path will only be resolved once the first time an icon is resolved and then it'll be cached. This means that all subsequent icons will take an incorrect path.

Related to angular#13628.
const elementsWithFuncIri = element.querySelectorAll(funcIriAttributeSelector);
const path = this._location.pathname ? this._location.pathname.split('#')[0] : '';
const elements = this._elementsWithExternalReferences =
Copy link
Member

Choose a reason for hiding this comment

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

Why not just initialize _elementsWithExternalReferences as an empty Map?

Copy link
Member Author

Choose a reason for hiding this comment

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

I did it so we can check for its presence in ngAfterViewChecked, rather than having to check the size. I'm not sure whether I'm not micro-optimizing it though.

private _previousPath?: string;

/** Keeps track of the elements and attributes that we've prefixed with the current path. */
private _elementsWithExternalReferences?: Map<Element, {name: string, value: string}[]>;
Copy link
Member

Choose a reason for hiding this comment

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

It looks like you reuse this as cachedElements in the ngAfterViewChecked method so that its a shorter name, should we just use cachedElements as the property name?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that calling the property cachedElements is a little too generic.

@josephperrott josephperrott merged commit df9ec74 into angular:master Oct 18, 2018
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants