tricknotes / ember-cli-rails

Unify your EmberCLI and Rails Workflows
http://thoughtbot.github.io/ember-cli-rails/
MIT License
713 stars 205 forks source link

`assets/vendor.js` is not found (variation of #120) #438

Closed simsalabim closed 8 years ago

simsalabim commented 8 years ago

This is one more circle on #120. Augmented precious comment to match new issue report template.

The gist: assets/vendor.js is not found approximately 80% of the times when you hit ember-cli route (in my case, "/"). The issue affects all environments.

Which operating system and version is the project developed on? OS X 10.10.5

Which version of ruby is the project developed on? MRI 2.3.0

Which version of npm is the project developed on? 2.14.12

Which version of ember-cli is the project developed on?

ember -v
version: 2.3.0
node: 4.3.1
os: darwin x64

What is the rails version? 5.0.0.beta2

What is the ember-cli-rails version (from Gemfile)? 0.7.3

What is the ember-cli-rails-addon version (from package.json)? 0.7.0

What are the contents of config/initializers/ember.rb?

EmberCli.configure do |c|
   c.app :frontend, path: "frontend"
end

What are the contents of the Rails' view that renders the Ember application?

<%= render_ember_app :frontend do |head, body| %>
  <% head.append do %>
    <%= csrf_meta_tags %>
  <% end %>
<% end %>
<nav>Custom navigation that is rendered from within Rails</nav>

How are the EmberCLI-related routes defined?

mount_ember_app :frontend, to: "/"

How is the application deployed? git push heroku master. Unsure it's related since the issue affects all envs, including development.

seanpdoyle commented 8 years ago

@simsalabim thanks for porting the issue into the template.

<%= render_ember_app :frontend do |head, body| %>
  <% head.append do %>
    <%= csrf_meta_tags %>
  <% end %>
<% end %>
<nav>Custom navigation that is rendered from within Rails</nav>

At first glance, this snippet jumps out at me.

The render_ember_app helper works by taking the output of ember build and serving through Rails' view layer, as a full-formed HTML document.

This means that your <nav> element (which I assume in this example is a placeholder for the rest of your Rails view code) exists outside of your response's <html></html> elements, and will cause the response to be invalid/malformed HTML.

It might not be the source of your issue, but it's worth keeping in mind.

Outside of that, could you try running rake ember:install before serving your application through rails server? I have a hunch some dependencies might be missing, which could cause the build process to fail.

I'm surprised it's failing silently, but if we're able to confirm my suspicions then we can investigate further.

simsalabim commented 8 years ago

@seanpdoyle I changed the template to be precisely

<%= render_ember_app :frontend do |head, body| %>
  <% head.append do %>
    <%= csrf_meta_tags %>
  <% end %>
<% end %>

and ran rake ember:install.

It did not change behavior. The page still loads sporadically, with approximately 20% success rate. What else can it be?

simsalabim commented 8 years ago

It doesn't fail silently. The issue is that assets/vendor.js couldn't be found at page load, despite the route works in isolation. I.e. if I open it in browser, it will render js file.

I don't know how helpful it can be, but here's the stack trace

Started GET "/" for ::1 at 2016-04-18 09:28:11 -0500
  ActiveRecord::SchemaMigration Load (0.4ms)  SELECT "schema_migrations".* FROM "schema_migrations"
Processing by EmberCli::EmberController#index as HTML
  Parameters: {"ember_app"=>:frontend}
version: 2.3.0
Building...

Build successful - 3574ms.

Slowest Trees                                 | Total
----------------------------------------------+---------------------
Babel                                         | 603ms
Babel                                         | 340ms
Babel                                         | 254ms

Slowest Trees (cumulative)                    | Total (avg)
----------------------------------------------+---------------------
Babel (12)                                    | 1822ms (151 ms)

  Rendered inline template (0.3ms)
  Rendered ember_cli/ember/index.html.erb (6919.7ms)
Completed 200 OK in 6942ms (Views: 6925.4ms | ActiveRecord: 0.0ms)
Started GET "/assets/vendor.css" for ::1 at 2016-04-18 09:28:18 -0500
Started GET "/assets/ab-survey-frontend.css" for ::1 at 2016-04-18 09:28:18 -0500
Started GET "/assets/ab-survey-frontend.js" for ::1 at 2016-04-18 09:28:18 -0500
Started GET "/assets/vendor.js" for ::1 at 2016-04-18 09:28:18 -0500

ActionController::RoutingError (No route matches [GET] "/assets/vendor.js"):
  actionpack (5.0.0.beta2) lib/action_dispatch/middleware/debug_exceptions.rb:53:in `call'

Also, vendor.js is being loaded after the application script. Which in turn is weird because I see that assets seemingly should be ordered

seanpdoyle commented 8 years ago

The page still loads sporadically, with approximately 20% success rate.

Are you serving from multi-process servers in development?

simsalabim commented 8 years ago

I am, here's the puma config

# config/puma.rb
threads_count = 1
threads threads_count, threads_count
port ENV.fetch("PORT") { 3000 }
environment ENV.fetch("RAILS_ENV") { "development" }
workers 1
preload_app!

Commenting out workers + preload_app! doesn't change anything in behavior.

seanpdoyle commented 8 years ago

@simsalabim I'm sorry, but at this point, a root cause isn't obvious.

Would you be interested in forking https://github.com/seanpdoyle/ember-cli-rails-heroku-example and modifying it so that the behavior you're seeing is reproduced?

If you're able to do that, we can inspect the git diff and go from there.

seanpdoyle commented 8 years ago

I'm closing this due to inactivity.

@simsalabim if you're still having this issue, please fork https://github.com/seanpdoyle/ember-cli-rails-heroku-example and try to reproduce your issue locally.

If you're able to do that, we can inspect the git diff and go from there.