Skip to content

Commit

Permalink
[BUGFIX LTS] Fix cyclic module crash
Browse files Browse the repository at this point in the history
`@ember/engine/index` and `@ember/engine/instance` have circular dependencies on each other.

This would be OK, except that `instance.ts` is eagerly copying a class off `index.ts`, at a point in time where it might not actually be available.

Whether this bug hits you depends on which side of the pair gets evaluated first. I only happened hit it when testing an app with engines and fastboot on Ember 5.

This fix is to not eagerly pull the class off the module.

(cherry picked from commit 7c31ada)
  • Loading branch information
ef4 authored and kategengler committed Jun 12, 2023
1 parent 06735db commit b40f7f3
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions packages/@ember/engine/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import type Application from '@ember/application';
import type { BootEnvironment } from '@ember/-internals/glimmer';
import type { SimpleElement } from '@simple-dom/interface';

const CEngine = Engine;

export interface BootOptions {
isBrowser?: boolean;
shouldRender?: boolean;
Expand Down Expand Up @@ -202,17 +200,17 @@ class EngineInstance extends EmberObject.extend(RegistryProxyMixin, ContainerPro
@return {EngineInstance,Error}
*/
buildChildEngineInstance(name: string, options: EngineInstanceOptions = {}): EngineInstance {
let Engine = this.lookup(`engine:${name}`);
let ChildEngine = this.lookup(`engine:${name}`);

if (!Engine) {
if (!ChildEngine) {
throw new Error(
`You attempted to mount the engine '${name}', but it is not registered with its parent.`
);
}

assert('expected an Engine', Engine instanceof CEngine);
assert('expected an Engine', ChildEngine instanceof Engine);

let engineInstance = Engine.buildInstance(options);
let engineInstance = ChildEngine.buildInstance(options);

setEngineParent(engineInstance, this);

Expand Down

0 comments on commit b40f7f3

Please sign in to comment.