Skip to content

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

Merged
josephperrott merged 1 commit into
angular:masterfrom
crisbeto:icon-outdated-path
Oct 18, 2018
Merged

fix(icon): not taking current path after initialization#13641
josephperrott merged 1 commit into
angular:masterfrom
crisbeto:icon-outdated-path

Conversation

@crisbeto

Copy link
Copy Markdown
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.

@crisbetocrisbeto added the target: patch This PR is targeted for the next patch release label Oct 17, 2018
@googlebotgooglebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Oct 17, 2018

@jelbournjelbourn left a comment

Copy link
Copy Markdown
Contributor

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.
Comment threadsrc/lib/icon/icon.ts
private _cacheChildrenWithExternalReferences(element: SVGElement) {
const elementsWithFuncIri = element.querySelectorAll(funcIriAttributeSelector);
const path = this._location.pathname ? this._location.pathname.split('#')[0] : '';
const elements = this._elementsWithExternalReferences =

Copy link
Copy Markdown
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
Copy Markdown
MemberAuthor

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.

Comment threadsrc/lib/icon/icon.ts
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
Copy Markdown
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
Copy Markdown
MemberAuthor

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:masterOct 18, 2018
@angular-automatic-lock-bot

Copy link
Copy Markdown

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-botangular-automatic-lock-botBot locked and limited conversation to collaborators Sep 9, 2019
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: mergeThe PR is ready for merge by the caretakercla: yesPR author has agreed to Google's Contributor License Agreementtarget: patchThis PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@crisbeto@jelbourn@josephperrott@googlebot