Skip to content

Duplicate call to createRenderer in ComponentFactory.create #47980

Closed

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

Activity

  1. self-assigned this
    on Nov 6, 2022
  2. added
    area: core
    on Nov 6, 2022
  3. modified the milestone: needsTriage on Nov 6, 2022
  4. added a commit that references this issue on Nov 6, 2022
    281ff6c
  5. added a commit that references this issue on Nov 7, 2022
    c3bc035
  6. added a commit that references this issue on Nov 7, 2022
    3e490fa
  7. angular-automatic-lock-bot commented on Dec 8, 2022

    @angular-automatic-lock-bot

    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.

  8. locked and limited conversation to collaborators on Dec 8, 2022
  9. added a commit that references this issue on Feb 1, 2023
    1a1be2f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: corestate: has PR

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions