question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[3.1.0] Cannot read property 'fullName' of undefined

See original GitHub issue

We have the following (maybe hacky?) code:

import Service from '@ember/service'
import Component from '@ember/component'
import { getOwner, setOwner } from '@ember/application'
import { Promise } from 'rsvp'

export default Service.extend
  _getRenderer: (owner) ->
    owner.lookup('renderer:-dom')

  render: (template, context) ->
    new Promise (resolve) =>
      # create a new component
      owner = getOwner(this)

      component = Component.create
        style: 'display:none;' # hide it
        layout: Ember.HTMLBars.compile(template)
        renderer: @_getRenderer(owner)
      setOwner(component, owner)

      component.setProperties(context)

      component.one 'didRender', ->
        element = @element.cloneNode(true)
        component.destroy()
        resolve(element)

      # append the component to the body to make it render
      component.append()

This used to work fine until (including) 3.0.0. 3.1.0 broke it - calling “append” leads to:

Uncaught TypeError: Cannot read property 'fullName' of undefined
    at new RootComponentDefinition (ember-glimmer.js:4485)
    at InteractiveRenderer.appendTo (ember-glimmer.js:4702)
    at Class.exports.default._emberMetal.Mixin.create._Mixin$create.appendTo (view_support.js:135)
    at Class.exports.default._emberMetal.Mixin.create._Mixin$create.append (view_support.js:139)
    at Ember.RSVP.Promise.resolve (template-to-dom.js:31)
    ...

It is blowing up because var factory = _container.FACTORY_FOR.get(component); returns undefined (for the component that we create in the code above).

I know we are using somewhat private APIs (append) but what has changed in the new Ember and how do we fix it?

Thanks for the great framework!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rwjbluecommented, Apr 11, 2018

The error is essentially because the component you are creating and rendering is not being created through the normal owner interface (you have already worked around a similar issue when you added this._getRenderer and manually setting owner).

The quickest work around for you would be (sorry gotta use JS since my coffeescript is super bad):

export default Service.extend({
  init() {
    this._super(...arguments);
    let owner = getOwner(this);
    owner.register('component:-special-snow-flake', Component);
  }
  render(template, context) {
    // ...snip...
    let owner = getOwner(this);
    let ComponentFactory = owner.factoryFor('component:-special-snowflake');
    let component = ComponentFactory.create({
      style: 'display:none',
      layout: Ember.HTMLBars.compile(template),
    });
    // ...snip...
  }
 });

This lets you remove the manual population of renderer and owner (I believe), but the code here still seems pretty non-idiomatic and brittle to other future framework changes. I’d suggest trying to come up with a way to refactor away from this pattern…

0reactions
houfeng0923commented, Jul 3, 2018

hi, @rwjblue , i had the same problem. thanks for your solution .

first, this source code , and can we update by adding Null check to suppress error ?

this.state = {
      name:  factory!.fullName.slice(10), //  update : factory && factory.fullName.slice(10),
      capabilities: ROOT_CAPABILITIES,
      ComponentClass: factory as Factory<any, any>,
      handle: null,
    };

although i accept to declare component in ember way , we can’t prevent the create invoked .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Push fails in GitKraken with errormessage ... - Stack Overflow
Push fails in GitKraken with errormessage "Push Failed cannot read property 'fullName' of undefined" · Ask Question. Asked 5 years, 9 months ago....
Read more >
Push Fails In Gitkraken With Errormessage "Push ... - ADocLib
Js Typeerror: Cannot Read Property 'Fullname' Of Undefined. JavaScript TypeError is thrown when an operand or argument passed to a function is incompatible....
Read more >
error typeerror: cannot read properties of undefined ... - You.com
The "Cannot read property 'includes' of undefined" error occurs when calling the includes() method on an undefined value. To solve the error, make...
Read more >
TypeScript Deep Dive
TypeScript Deep Dive is one of the best technical texts I've read in a while. ... TypeScript team doesn't use null : TypeScript...
Read more >
Bug listing with status RESOLVED with resolution TEST ...
... Bug:19759 - "rc4 CD boots up to install and doesn't detect either ... fails with undefined reference to OtsMove" status:RESOLVED resolution:TEST-REQUEST ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found