Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

includeRoutesInApplication option does not initialize the lazy engine routes #738

Open
AbhinavVishak opened this issue Dec 3, 2020 · 10 comments

Comments

@AbhinavVishak
Copy link

AbhinavVishak commented Dec 3, 2020

ember new separate-route
cd separate-route
ember install ember-engines
ember generate in-repo-engine lazy-engine

Change the lazyLoading option to { enabled: true, includeRoutesInApplication: false } in lib/lazy-engine/index.js
Add a simple console.log('foobar') inside the buildRoutes function in lib/lazy-engine/addon/routes.js
ember s
go to localhost:4200/lazy-engine

The console log never shows up. Adding a breakpoint/logpoint on the define("lazy-engine/routes") triggers the define statement however.

@gtb104
Copy link

gtb104 commented Dec 3, 2020

I created a reproduction (https://github.com/gtb104/lazy-engine).

In it I've defined:

  lazyLoading: Object.freeze({
    enabled: true,
    includeRoutesInApplication: false
  })

When the app loads in the browser, I get the following error:
Uncaught (in promise) Error: Assertion Failed: You attempted to generate a link for the "foo" route, but did not pass the models required for generating its dynamic segments. There is no route named lazy-engine.foo

What I expect to happen is the link to create successfully, and to properly route to the "foo" route when clicked.

@gtb104
Copy link

gtb104 commented Dec 5, 2020 via email

@villander
Copy link
Member

@gtb104 @AbhinavVishak I'm not sure if this behavior is unexpected, given we don't any documentation clear about this attribute I can see in the codebase that we have a JS doc saying that when this attribute is false we don't want to promote the routes into the host.

What the behavior expected here? Is there another version of ember-engines where it worked as you expected?

// The treeForEngine method constructs and returns a tree that represents
// the engines routes.js file and its dependencies. This is used later to
// promote the engines routes.js to the host.
//
// If the lazyLoading.includeRoutesInApplication option is false, we don't
// want to promote the routes into the host.
this.treeForEngine = function() {

@gtb104
Copy link

gtb104 commented Dec 5, 2020 via email

@villander
Copy link
Member

villander commented Dec 20, 2020

This will enable engines to be discovered dynamically at runtime rather than requiring engines to be declared statically at build time.

For sure this behavior isn't supported to ember-engines, all things on manifest.json to load engines are created on build time.

could you please clarify the expected behavior of includeRoutesInApplication @rwjblue @dgeb? I never used it.

@villander
Copy link
Member

@dgeb @bertdeblock any thoughts here?

@gtb104
Copy link

gtb104 commented Jul 6, 2021

I've moved on to another project, and it looks like this is dead, so it can be closed.

@daniellubovich
Copy link

I'm also curious about the intended behavior of includeRoutesInApplication - anyone have insight into this? Maybe @mike183? Just a shot in the dark since I know it's been like six years.

@mike183
Copy link
Contributor

mike183 commented Feb 17, 2023

@daniellubovich It's been a long time since I used ember-engines, but as far as I can remember, the intention of this feature was to allow an engine's route definitions to be included within it's own build output, instead of being bundled with the parent application.

This main motivator for this being to enable engines to be built in isolation, and also allow them to be side-loaded into an Ember.js application, without the engine itself needing to be present at build time of the parent application.

This effectively meant that you could use engines to dynamically extend an Ember.js application at runtime.

Hope that makes sense 🙂

@daniellubovich
Copy link

@mike183 Ah, okay that totally makes sense. I had assumed there was something in ember-engines that would automatically load up these routes files when the router encountered a lazy-loaded engine that hadn't yet been loaded. Sounds like that's not the case - this just handles keeping the routes separate at build-time, and I'd probably need to do something custom in my app to load them up at runtime?

Either way, this clears things up. Thanks for the reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants