Skip to content

Commit b40f7f3

Browse files
ef4kategengler
authored andcommitted
[BUGFIX LTS] Fix cyclic module crash
`@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)
1 parent 06735db commit b40f7f3

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

packages/@ember/engine/instance.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import type Application from '@ember/application';
1717
import type { BootEnvironment } from '@ember/-internals/glimmer';
1818
import type { SimpleElement } from '@simple-dom/interface';
1919

20-
const CEngine = Engine;
21-
2220
export interface BootOptions {
2321
isBrowser?: boolean;
2422
shouldRender?: boolean;
@@ -202,17 +200,17 @@ class EngineInstance extends EmberObject.extend(RegistryProxyMixin, ContainerPro
202200
@return {EngineInstance,Error}
203201
*/
204202
buildChildEngineInstance(name: string, options: EngineInstanceOptions = {}): EngineInstance {
205-
let Engine = this.lookup(`engine:${name}`);
203+
let ChildEngine = this.lookup(`engine:${name}`);
206204

207-
if (!Engine) {
205+
if (!ChildEngine) {
208206
throw new Error(
209207
`You attempted to mount the engine '${name}', but it is not registered with its parent.`
210208
);
211209
}
212210

213-
assert('expected an Engine', Engine instanceof CEngine);
211+
assert('expected an Engine', ChildEngine instanceof Engine);
214212

215-
let engineInstance = Engine.buildInstance(options);
213+
let engineInstance = ChildEngine.buildInstance(options);
216214

217215
setEngineParent(engineInstance, this);
218216

0 commit comments

Comments
 (0)