ember-basic-dropdown icon indicating copy to clipboard operation
ember-basic-dropdown copied to clipboard

`destinationElement` null or undefined exception

Open alexdiliberto opened this issue 4 years ago • 9 comments

Uncaught (in promise) Error: Assertion Failed: You cannot pass a null or undefined destination element to in-element
    at assert (index.js:172)
    at InElementNullCheckReference.value (index.js:5796)
    at Object.evaluate (runtime.js:2288)
    at AppendOpcodes.evaluate (runtime.js:1571)
    at LowLevelVM.evaluateSyscall (runtime.js:4989)
    at LowLevelVM.evaluateInner (runtime.js:4945)
    at LowLevelVM.evaluateOuter (runtime.js:4937)
    at JitVM.next (runtime.js:5992)
    at JitVM.execute (runtime.js:5964)
    at TemplateIteratorImpl.sync (runtime.js:6124)

There may be other ways to trigger this, but you will definitely see the issue if you use this in conjunction with Ember Power Select. Create a new app and add the following respectively to your application controller and application template

import Controller from '@ember/controller';

export default class ApplicationController extends Controller {
  names = ['One', 'Two', 'Three']
}
<PowerSelect
  @searchEnabled={{true}}
  @options={{this.names}}
  @selected={{this.name}}
  @placeholder="Select some names..."
  @initiallyOpened={{true}}
  @onChange={{fn (mut this.name)}} as |name|>
  {{name}}
</PowerSelect>

@initiallyOpened={{true}} is the issue here. I traced the issue down to this line: https://github.com/cibernox/ember-basic-dropdown/blob/v3.0.17/addon/templates/components/basic-dropdown-content.hbs#L4

this.destinationElement is null at this moment and will throw when attempting to render into ember-basic-dropdown-wormhole DOM element since that is rendering later in DOM ordor (at the end of the page)

I took at stab at updating to ensure destinationElement is populated but not sure if this will cause any additional issues. Perhaps someone with a bit more intimate knowledge here will be able to advise.

  @tracked destinationElement: Element | null;

  constructor(owner: unknown, args: Args) {
    super(owner, args);

    this.destinationElement = null;
    next(() => {
      this.destinationElement = document.getElementById(this.args.destination);
    });
  }

this is related to https://github.com/cibernox/ember-power-select/issues/1354

alexdiliberto avatar May 17 '21 20:05 alexdiliberto

I am getting the same error when using named blocks.

jgadbois avatar Jun 02 '21 15:06 jgadbois

Can you write a reproduction on a test? This is probably easy to fix with a repro on a test.

cibernox avatar Jun 02 '21 15:06 cibernox

@cibernox See https://github.com/cibernox/ember-basic-dropdown/pull/619

alexdiliberto avatar Jun 03 '21 16:06 alexdiliberto

I am getting the error using a very basic dropdown directly in the application.hbs.

<BasicDropdown as |dd|
>
  <dd.Trigger>TEST</dd.Trigger>
  <dd.Content>CONTENT</dd.Content>
</BasicDropdown>

@renderInPlace={{true}} fixes it, but breaks when rendered on the body.

jgadbois avatar Jul 15 '21 13:07 jgadbois

Reverting to 3.0.18 fixed this for me

jgadbois avatar Jul 15 '21 13:07 jgadbois

Is there a solution outside of @renderInPlace={{true}}?

jherdman avatar Oct 06 '21 14:10 jherdman

Also seeing this error.

josemarluedke avatar Jan 25 '22 22:01 josemarluedke

Ran into this as well. Based on this and https://github.com/cibernox/ember-power-select/issues/1354, I was able to get this workaround going in tests.

<PowerSelect
  // other args
  @initiallyOpened={{false}}
  @renderInPlace={{true}}
  as |stuff|
>
  {{stuff.andThings}}
</PowerSelect>

sacarino avatar May 23 '22 13:05 sacarino

I encountered this error while updating ember-cached-decorator-polyfill from 0.1.4 to 1.0.1 in our app. I was able to track it down to this issue https://github.com/emberjs/ember-classic-decorator/issues/99.

If you are still experiencing this issue, check if you have ember-classic-decorator in your dependencies.

andreyfel avatar Jan 24 '23 17:01 andreyfel