Skip to content

Duplicate call to createRenderer in ComponentFactory.create #47980

@4javier

Description

@4javier

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

No

Description

ComponentFactory.create code looks like calling the same function with the same parameters twice.

const hostRenderer = rendererFactory.createRenderer(null, this.componentDef);
// Determine a tag name used for creating host elements when this component is created
// dynamically. Default to 'div' if this component did not specify any tag name in its selector.
const elementName = this.componentDef.selectors[0][0] as string || 'div';
const hostRNode = rootSelectorOrNode ?
locateHostElement(hostRenderer, rootSelectorOrNode, this.componentDef.encapsulation) :
createElementNode(
rendererFactory.createRenderer(null, this.componentDef), elementName,
getNamespace(elementName));

First at line 166 the renderer is created and assigned to hostRenderer, then in falsy branch of ternary assignment hostRNode = rootSelectorOrNode it gets created again and passed as first argument of createElementNode at line 173.

Even if Renderer2 implementations are usually smart enough to cache renderers, there's always a (IMHO) useless repetition of the call, thus an unneeded access to cache map.

Strange thing is that it gets referenced correctly as first argument of locateHostElement call for truthy branch.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in (run ng version)

No response

Anything else?

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions