komposable / komponent

An opinionated way of organizing front-end code in Ruby on Rails, based on components
http://komponent.io
MIT License
427 stars 31 forks source link

uninitialized constant ButtonComponent #121

Closed nicolas-brousse closed 5 years ago

nicolas-brousse commented 5 years ago

Sometimes I got this kind of exception on production projects.
But I've no idea of what is causes this. I didn't have similar exception on other classes than Component classes.

Does it something you already noticed?

ActionView::Template::Error: uninitialized constant PageComponent
Did you mean?  PagesController
NameError: uninitialized constant PageComponent
Did you mean?  PagesController
  from active_support/inflector/methods.rb:283:in `const_get'
  from active_support/inflector/methods.rb:283:in `block in constantize'
  from active_support/inflector/methods.rb:281:in `each'
  from active_support/inflector/methods.rb:281:in `inject'
  from active_support/inflector/methods.rb:281:in `constantize'
  from active_support/core_ext/string/inflections.rb:68:in `constantize'
  from komponent/component_renderer.rb:41:in `_render'
  from komponent/component_renderer.rb:28:in `render'
  from komponent/komponent_helper.rb:8:in `component'
  from app/views/layouts/application.html.slim:56:in `block in _app_views_layouts_application_html_slim__67813829245616579_47247190532600'
  from action_view/helpers/capture_helper.rb:41:in `block in capture'
  from action_view/helpers/capture_helper.rb:205:in `with_output_buffer'
  from action_view/helpers/capture_helper.rb:41:in `capture'
  from komponent/komponent_helper.rb:5:in `block in component'
  from action_view/helpers/capture_helper.rb:41:in `block in capture'
  from action_view/helpers/capture_helper.rb:205:in `with_output_buffer'
  from action_view/helpers/capture_helper.rb:41:in `capture'
  from action_view/helpers/rendering_helper.rb:93:in `_layout_for'
  from action_view/renderer/partial_renderer.rb:345:in `block (2 levels) in render_partial'
  from container/_container.html.slim:2:in `block in _frontend_components_container__container_html_slim___3819109131142581335_47247196460080'
  from action_view/helpers/capture_helper.rb:41:in `block in capture'
  from action_view/helpers/capture_helper.rb:205:in `with_output_buffer'
  from action_view/helpers/capture_helper.rb:41:in `capture'
  from action_view/helpers/tag_helper.rb:272:in `content_tag'
  from container/_container.html.slim:1:in `_frontend_components_container__container_html_slim___3819109131142581335_47247196460080'
  from action_view/template.rb:159:in `block in render'
  from active_support/notifications.rb:170:in `instrument'
  from action_view/template.rb:354:in `instrument_render_template'
  from action_view/template.rb:157:in `render'
  from action_view/renderer/partial_renderer.rb:344:in `block in render_partial'
  from action_view/renderer/abstract_renderer.rb:44:in `block in instrument'
  from active_support/notifications.rb:170:in `instrument'
  from action_view/renderer/abstract_renderer.rb:43:in `instrument'
  from action_view/renderer/partial_renderer.rb:333:in `render_partial'
  from action_view/renderer/partial_renderer.rb:312:in `render'
  from action_view/renderer/renderer.rb:49:in `render_partial'
  from action_view/helpers/rendering_helper.rb:37:in `render'
  from komponent/component_renderer.rb:71:in `_render'
  from komponent/component_renderer.rb:28:in `render'
  from komponent/komponent_helper.rb:8:in `component'
  from app/views/layouts/application.html.slim:54:in `_app_views_layouts_application_html_slim__67813829245616579_47247190532600'
  from action_view/template.rb:159:in `block in render'
  from active_support/notifications.rb:170:in `instrument'
  from action_view/template.rb:354:in `instrument_render_template'
  from action_view/template.rb:157:in `render'
  from action_view/renderer/template_renderer.rb:66:in `render_with_layout'
  from action_view/renderer/template_renderer.rb:52:in `render_template'
  from action_view/renderer/template_renderer.rb:16:in `render'
  from action_view/renderer/renderer.rb:44:in `render_template'
  from action_view/renderer/renderer.rb:25:in `render'
  from action_view/rendering.rb:103:in `_render_template'
  from action_controller/metal/streaming.rb:219:in `_render_template'
  from action_view/rendering.rb:84:in `render_to_body'
  from action_controller/metal/rendering.rb:52:in `render_to_body'
  from action_controller/metal/renderers.rb:142:in `render_to_body'
  from abstract_controller/rendering.rb:25:in `render'
  from action_controller/metal/rendering.rb:36:in `render'
  from action_controller/metal/instrumentation.rb:46:in `block (2 levels) in render'
  from active_support/core_ext/benchmark.rb:14:in `block in ms'
  from benchmark.rb:308:in `realtime'
  from active_support/core_ext/benchmark.rb:14:in `ms'
  from action_controller/metal/instrumentation.rb:46:in `block in render'
  from action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
  from active_record/railties/controller_runtime.rb:31:in `cleanup_view_runtime'
  from action_controller/metal/instrumentation.rb:45:in `render'
  from action_controller/responder.rb:238:in `default_render'
  from action_controller/responder.rb:170:in `to_html'
  from action_controller/responder.rb:163:in `respond'
  from action_controller/responder.rb:156:in `call'
  from action_controller/respond_with.rb:211:in `respond_with'
  from devise/sessions_controller.rb:14:in `new'
  from action_controller/metal/basic_implicit_render.rb:6:in `send_action'
  from abstract_controller/base.rb:194:in `process_action'
  from action_controller/metal/rendering.rb:30:in `process_action'
  from abstract_controller/callbacks.rb:42:in `block in process_action'
  from active_support/callbacks.rb:109:in `block in run_callbacks'
  from raven/integrations/rails/controller_transaction.rb:7:in `block in included'
  from active_support/callbacks.rb:118:in `instance_exec'
  from active_support/callbacks.rb:118:in `block in run_callbacks'
  from active_support/callbacks.rb:136:in `run_callbacks'
  from abstract_controller/callbacks.rb:41:in `process_action'
  from action_controller/metal/rescue.rb:22:in `process_action'
  from action_controller/metal/instrumentation.rb:34:in `block in process_action'
  from active_support/notifications.rb:168:in `block in instrument'
  from active_support/notifications/instrumenter.rb:23:in `instrument'
  from active_support/notifications.rb:168:in `instrument'
  from action_controller/metal/instrumentation.rb:32:in `process_action'
  from action_controller/metal/params_wrapper.rb:256:in `process_action'
  from active_record/railties/controller_runtime.rb:24:in `process_action'
  from abstract_controller/base.rb:134:in `process'
  from action_view/rendering.rb:32:in `process'
  from action_controller/metal.rb:191:in `dispatch'
  from action_controller/metal.rb:252:in `dispatch'
  from action_dispatch/routing/route_set.rb:52:in `dispatch'
  from action_dispatch/routing/route_set.rb:34:in `serve'
  from action_dispatch/routing/mapper.rb:18:in `block in <class:Constraints>'
  from action_dispatch/routing/mapper.rb:48:in `serve'
  from action_dispatch/journey/router.rb:52:in `block in serve'
  from action_dispatch/journey/router.rb:35:in `each'
  from action_dispatch/journey/router.rb:35:in `serve'
  from action_dispatch/routing/route_set.rb:840:in `call'
  from http_accept_language/middleware.rb:14:in `call'
  from rack/deflater.rb:34:in `call'
  from rack/attack.rb:181:in `call'
  from warden/manager.rb:36:in `block in call'
  from warden/manager.rb:35:in `catch'
  from warden/manager.rb:35:in `call'
  from rack/tempfile_reaper.rb:15:in `call'
  from rack/etag.rb:25:in `call'
  from rack/conditional_get.rb:25:in `call'
  from rack/head.rb:12:in `call'
  from action_dispatch/http/content_security_policy.rb:18:in `call'
  from rack/session/abstract/id.rb:232:in `context'
  from rack/session/abstract/id.rb:226:in `call'
  from action_dispatch/middleware/cookies.rb:670:in `call'
  from action_dispatch/middleware/callbacks.rb:28:in `block in call'
  from active_support/callbacks.rb:98:in `run_callbacks'
  from action_dispatch/middleware/callbacks.rb:26:in `call'
  from action_dispatch/middleware/debug_exceptions.rb:61:in `call'
  from action_dispatch/middleware/show_exceptions.rb:33:in `call'
  from lograge/rails_ext/rack/logger.rb:15:in `call_app'
  from rails/rack/logger.rb:26:in `block in call'
  from active_support/tagged_logging.rb:71:in `block in tagged'
  from active_support/tagged_logging.rb:28:in `tagged'
  from active_support/tagged_logging.rb:71:in `tagged'
  from rails/rack/logger.rb:26:in `call'
  from sprockets/rails/quiet_assets.rb:13:in `call'
  from action_dispatch/middleware/remote_ip.rb:81:in `call'
  from request_store/middleware.rb:19:in `call'
  from action_dispatch/middleware/request_id.rb:27:in `call'
  from rack/method_override.rb:22:in `call'
  from rack/runtime.rb:22:in `call'
  from active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
  from action_dispatch/middleware/executor.rb:14:in `call'
  from action_dispatch/middleware/static.rb:127:in `call'
  from rack/sendfile.rb:111:in `call'
  from action_dispatch/middleware/ssl.rb:74:in `call'
  from raven/integrations/rack.rb:51:in `call'
  from rails/engine.rb:524:in `call'
  from puma/configuration.rb:225:in `call'
  from puma/server.rb:658:in `handle_request'
  from puma/server.rb:472:in `process_client'
  from puma/server.rb:332:in `block in run'
  from puma/thread_pool.rb:133:in `block in spawn_thread'
Spone commented 5 years ago

Thanks @nicolas-brousse for the report!

We need to investigate this. Please let us know if you have more information.

@sigmike @florentferry any idea about what could be the cause of this?

dmkl commented 5 years ago

@Spone I have the same issue. I cannot reproduce it, but it happens in production sporadically few times a day. Please help!

nicolas-brousse commented 5 years ago

Hi @dmkl.

I have some questions that may help us to know where to search.

In our project we still have the issue, but the Component is not always the same. I don't know if it's related when the application is started and for the first request, but it may be the case.

For our project we use the following:

dmkl commented 5 years ago

@nicolas-brousse sure:

I cannot find any correlation between occurrences. It doesn't seem to be related to server restarts.

…esupport-5.2.0/lib/active_support/inflector/methods.rb: 283:in `const_get'
…esupport-5.2.0/lib/active_support/inflector/methods.rb: 283:in `block in constantize'
…esupport-5.2.0/lib/active_support/inflector/methods.rb: 281:in `each'
…esupport-5.2.0/lib/active_support/inflector/methods.rb: 281:in `inject'
…esupport-5.2.0/lib/active_support/inflector/methods.rb: 281:in `constantize'
….2.0/lib/active_support/core_ext/string/inflections.rb:  68:in `constantize'
…ms/komponent-2.2.0/lib/komponent/component_renderer.rb:  41:in `_render'
…ms/komponent-2.2.0/lib/komponent/component_renderer.rb:  28:in `render'
…gems/komponent-2.2.0/lib/komponent/komponent_helper.rb:   8:in `component'
/app/frontend/components/root_page/_root_page.html.slim:9
...
nicolas-brousse commented 5 years ago

@dmk thanks for this info. It give us more visibility, but it still a weird issue. I'll try to take some time to try to understand what happen.

I have to take a bit of time in our sentry to check if the error appear less often since we moved from 2.5.3 to 2.6.1.

Spone commented 5 years ago

Hi @dmkl,

we're wondering if we shouldn't eager load the component modules. That's how draper does it for instance: https://github.com/drapergem/draper/blob/master/lib/draper/railtie.rb#L15

See these links on the topic:

Could you try replacing:

config.autoload_paths << config.root.join("app/frontend/components")

with

config.paths.add "frontend/components", eager_load: true

in your app, and let us know if you still experience the error?

nicolas-brousse commented 5 years ago

I'll also do the update to check.

dmkl commented 5 years ago

@Spone, @nicolas-brousse thank you! I'll update to eager loading and let you know in a while if it helps.

dmkl commented 5 years ago

@Spone, @nicolas-brousse eager loading seems to resolve the issue. Since updating config settings to eager_load: true I didn't see this error for 3 weeks (ruby 2.5.3, Rails 5.2.0). Thank you!

nicolas-brousse commented 5 years ago

Yay! Sounds like a great news!

Thank you too for testing and let us know 🙂

Spone commented 5 years ago

Great, we'll add this in a future release! Thanks @dmkl