Skip to content

Commit

Permalink
Restore compatibility with Ember Engines previously fixed in #315
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemelia committed Jan 26, 2022
1 parent 45ee190 commit d52eb31
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion addon/instance-initializers/add-modals-container.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { getDestinationElementIdFromConfig } from 'ember-modal-dialog/utils/config-utils';
import Application, { getOwner } from '@ember/application';
import Engine from '@ember/engine';
import { assert } from '@ember/debug';

let hasDOM = typeof document !== 'undefined';

Expand All @@ -24,5 +27,17 @@ export default function (instance) {
let config = instance.resolveRegistration('config:environment');
let modalContainerElId = getDestinationElementIdFromConfig(config);

appendContainerElement(instance.rootElement, modalContainerElId);
let app;
if (instance instanceof Application) {
app = instance;
} else if (instance instanceof Engine) {
// As there is only a single `Router` across the whole app, which is owned
// by the root `Application`, this reliably finds the root `Application`
// from an`Engine`.
app = getOwner(getOwner(instance).lookup('service:router'));
} else {
assert(`Could not find the root Application for '${instance}'.`);
}

appendContainerElement(app.rootElement, modalContainerElId);
}

0 comments on commit d52eb31

Please sign in to comment.