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

JsRoutes do not re-compile when routes.rb changes #232

Open
adamrunner opened this Issue Dec 1, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@adamrunner

adamrunner commented Dec 1, 2017

We have a large scale production application that uses JS Routes heavily for all of the javascript paths. We have an "advanced" setup since we separate out our admin and non admin routes.

We have 2 routes.js.erb files configured to get parsed and then compiled as part of the asset compilation process.

However, what I've discovered is that when the routes change; the file does not get regenerated (unless it is removed from the sprockets cache). If I add any comments at the top of the routes.js.erb file; it gets reprocessed.

This seems like an order of operations issue; like sprockets is calculating the fingerprint / cache information of the file before ERB is changing the actual contents of the file.

@adamrunner adamrunner changed the title from JsRoutes do not re-compile when routes change to JsRoutes do not re-compile when routes.rb changes Dec 1, 2017

@bogdan

This comment has been minimized.

Show comment
Hide comment
@bogdan

bogdan Dec 4, 2017

Collaborator

I don't see a way to make that automatic.
JsRoutes can not guess the asset name that needs to be recompiled when routes.rb changes.

The way we can change that is by passing asset name into generate manually:

<%= JsRoutes.generate(asset_name: 'admin_routes.js.erb', ... %>

It will help JsRoutes to add a dependency to expire the asset by updates in routes.rb.

The alternative way would be specify dependency yourself, but I don't know how to do that yet:

// = depend_on config/routes.rb
<%= JsRoutes.generate %>

I will research for other ideas and post updates.

Collaborator

bogdan commented Dec 4, 2017

I don't see a way to make that automatic.
JsRoutes can not guess the asset name that needs to be recompiled when routes.rb changes.

The way we can change that is by passing asset name into generate manually:

<%= JsRoutes.generate(asset_name: 'admin_routes.js.erb', ... %>

It will help JsRoutes to add a dependency to expire the asset by updates in routes.rb.

The alternative way would be specify dependency yourself, but I don't know how to do that yet:

// = depend_on config/routes.rb
<%= JsRoutes.generate %>

I will research for other ideas and post updates.

@adamrunner

This comment has been minimized.

Show comment
Hide comment
@adamrunner

adamrunner Dec 4, 2017

For what it's worth, I'd also be ok writing a step in our deploy process that will remove the sprockets cached version of the file and force it to be generated; I can't imagine that enumerating the routes is all that computationally expensive.

adamrunner commented Dec 4, 2017

For what it's worth, I'd also be ok writing a step in our deploy process that will remove the sprockets cached version of the file and force it to be generated; I can't imagine that enumerating the routes is all that computationally expensive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment