lookbook-hq / lookbook

A UI development environment for Ruby on Rails apps ✨
https://lookbook.build
MIT License
883 stars 91 forks source link

X has been removed from the module tree but is still active error #152

Closed Jackson200 closed 1 year ago

Jackson200 commented 1 year ago

Hi all, I am getting the following error from time to time. I can't quite nail down the pattern. Any clues? Thanks in advance

ArgumentError

A copy of GroupComponents::WidgetComponentsPreview has been removed from the module tree but is still active!
/gems/ruby/3.0.0/gems/activesupport-6.1.6.1/lib/active_support/dependencies.rb [line 543]
def load_missing_constant(from_mod, const_name)
      from_mod_name = real_mod_name(from_mod)
      unless qualified_const_defined?(from_mod_name) && Inflector.constantize(from_mod_name).equal?(from_mod)
        raise ArgumentError, "A copy of #{from_mod} has been removed from the module tree but is still active!"
      end
      qualified_name = qualified_name_for(from_mod, const_name)
Full stack trace:
/gems/ruby/3.0.0/gems/activesupport-6.1.6.1/lib/active_support/dependencies.rb:543:in `load_missing_constant'
allmarkedup commented 1 year ago

@Jackson200 Hmm no, that is a new one to me. I suspect it is something to do with Rails' reloading of source files in dev, perhaps coupled with the preview object caching Lookbook does. Not quite sure why though! Although from a quick search there are a few references to this sort of issue in Rails without Lookbook so it sounds like there might be a few ways the issue could crop up.

Out of interest, have you explicitly added the directory with your preview classes in them to Rails' config.autoload_paths?

Jackson200 commented 1 year ago

Hi @allmarkedup and thanks for looking. I had a search on the issue before too, but since I had never came across it before I thought it may have been related to Lookbook. I don't have any preview directories in my config.autoload_paths

Rails.application.config.autoload_paths
=> ["/app/lib", "/app/app/workers"]

It seems I can make it go away by making a change on the component view, or just waiting.

allmarkedup commented 1 year ago

Hey @Jackson200 - it probably is indeed related to Lookbook, I'm guessing it is something to do with the timing of clearing the cache of preview objects after a change is made and Rails' reloading of source code at the same time.

You only have the first line of the stack trace in your message above - do you think you could copy and paste the whole thing in here for me next time you run into the issue? Then I can see if I can figure out what is going on.

Sorry that you seem to be running into all the bugs with Lookbook - I hope it's not proving too frustrating an experience!

Jackson200 commented 1 year ago

hi @allmarkedup I will do, regarding the stack trace.

Not too frustrating thanks! Being such a great tool makes up for any teething problems. Likewise for you though. I am sometimes hesitant to keep opening issues, because I'm unsure if it is LookBook, Rails, or user/config error on my part. So thanks for being so active in your replies and fixes.

allmarkedup commented 1 year ago

I am sometimes hesitant to keep opening issues, because I'm unsure if it is LookBook, Rails, or user/config error on my part.

No that is really no worries, I prefer to try and help where I can and I don't want to miss any bugs in Lookbook if at all possible! And even if it's not a Lookbook thing directly it might be something that other Lookbook users are running into too.

Let me know if you manage to grab a stack trace and I'll see if I can figure out what might be the culprit in the meantime.

Jackson200 commented 1 year ago

Thanks @allmarkedup. Here ya go!

To recreate:

  1. I had just created a new ViewComponent Class by copying an existing Class.
  2. I created the view and preview.
  3. When I tried to load the preview, I got the error that the Class didn't exist.
  4. Doh, I fixed the Class name and refreshed
  5. Voila

It seems I can make it go away by making a change on the component view, or just waiting.

This seems not to be true, but I have my reload issues, so YMMV :)

Screen Shot 2022-09-24 at 5 44 07 AM

Full stack trace:
/gems/ruby/3.0.0/gems/activesupport-6.1.6.1/lib/active_support/dependencies.rb:543:in `load_missing_constant'
/gems/ruby/3.0.0/gems/activesupport-6.1.6.1/lib/active_support/dependencies.rb:213:in `const_missing'
/app/spec/components/previews/player_profile_components_preview.rb:51:in `last_visit'
/gems/ruby/3.0.0/gems/view_component-2.61.1/lib/view_component/preview.rb:42:in `public_send'
/gems/ruby/3.0.0/gems/view_component-2.61.1/lib/view_component/preview.rb:42:in `render_args'
/gems/ruby/3.0.0/gems/lookbook-1.0.4/lib/lookbook/preview.rb:5:in `render_args'
/gems/ruby/3.0.0/gems/lookbook-1.0.4/app/controllers/lookbook/previews_controller.rb:130:in `block in inspector_data'
/gems/ruby/3.0.0/gems/lookbook-1.0.4/app/controllers/lookbook/previews_controller.rb:129:in `map'
/gems/ruby/3.0.0/gems/lookbook-1.0.4/app/controllers/lookbook/previews_controller.rb:129:in `inspector_data'
/gems/ruby/3.0.0/gems/lookbook-1.0.4/app/controllers/lookbook/previews_controller.rb:168:in `block in panels'
/gems/ruby/3.0.0/gems/lookbook-1.0.4/app/controllers/lookbook/previews_controller.rb:162:in `each'
/gems/ruby/3.0.0/gems/lookbook-1.0.4/app/controllers/lookbook/previews_controller.rb:162:in `panels'
/gems/ruby/3.0.0/gems/lookbook-1.0.4/app/controllers/lookbook/previews_controller.rb:183:in `main_panels'
/gems/ruby/3.0.0/gems/lookbook-1.0.4/app/controllers/lookbook/previews_controller.rb:37:in `show'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/abstract_controller/base.rb:228:in `process_action'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_controller/metal/rendering.rb:30:in `process_action'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/abstract_controller/callbacks.rb:42:in `block in process_action'
/gems/ruby/3.0.0/gems/activesupport-6.1.6.1/lib/active_support/callbacks.rb:117:in `block in run_callbacks'
/gems/ruby/3.0.0/gems/actiontext-6.1.6.1/lib/action_text/rendering.rb:20:in `with_renderer'
/gems/ruby/3.0.0/gems/actiontext-6.1.6.1/lib/action_text/engine.rb:59:in `block (4 levels) in <class:Engine>'
/gems/ruby/3.0.0/gems/activesupport-6.1.6.1/lib/active_support/callbacks.rb:126:in `instance_exec'
/gems/ruby/3.0.0/gems/activesupport-6.1.6.1/lib/active_support/callbacks.rb:126:in `block in run_callbacks'
/gems/ruby/3.0.0/gems/ahoy_matey-4.1.0/lib/ahoy/controller.rb:45:in `set_ahoy_request_store'
/gems/ruby/3.0.0/gems/activesupport-6.1.6.1/lib/active_support/callbacks.rb:126:in `block in run_callbacks'
/gems/ruby/3.0.0/gems/activesupport-6.1.6.1/lib/active_support/callbacks.rb:137:in `run_callbacks'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/abstract_controller/callbacks.rb:41:in `process_action'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_controller/metal/rescue.rb:22:in `process_action'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'
/gems/ruby/3.0.0/gems/activesupport-6.1.6.1/lib/active_support/notifications.rb:203:in `block in instrument'
/gems/ruby/3.0.0/gems/activesupport-6.1.6.1/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
/gems/ruby/3.0.0/gems/activesupport-6.1.6.1/lib/active_support/notifications.rb:203:in `instrument'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_controller/metal/instrumentation.rb:33:in `process_action'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_controller/metal/params_wrapper.rb:249:in `process_action'
/gems/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/railties/controller_runtime.rb:27:in `process_action'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/abstract_controller/base.rb:165:in `process'
/gems/ruby/3.0.0/gems/actionview-6.1.6.1/lib/action_view/rendering.rb:39:in `process'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_controller/metal.rb:190:in `dispatch'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_controller/metal.rb:254:in `dispatch'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_dispatch/routing/route_set.rb:33:in `serve'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_dispatch/journey/router.rb:50:in `block in serve'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_dispatch/journey/router.rb:32:in `each'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_dispatch/journey/router.rb:32:in `serve'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_dispatch/routing/route_set.rb:842:in `call'
/gems/ruby/3.0.0/gems/railties-6.1.6.1/lib/rails/engine.rb:539:in `call'
/gems/ruby/3.0.0/gems/railties-6.1.6.1/lib/rails/railtie.rb:207:in `public_send'
/gems/ruby/3.0.0/gems/railties-6.1.6.1/lib/rails/railtie.rb:207:in `method_missing'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_dispatch/routing/mapper.rb:20:in `block in <class:Constraints>'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_dispatch/routing/mapper.rb:49:in `serve'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_dispatch/journey/router.rb:50:in `block in serve'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_dispatch/journey/router.rb:32:in `each'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_dispatch/journey/router.rb:32:in `serve'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_dispatch/routing/route_set.rb:842:in `call'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_dispatch/middleware/static.rb:24:in `call'
/gems/ruby/3.0.0/gems/rack-2.2.4/lib/rack/static.rb:161:in `call'
/gems/ruby/3.0.0/gems/warden-1.2.9/lib/warden/manager.rb:36:in `block in call'
/gems/ruby/3.0.0/gems/warden-1.2.9/lib/warden/manager.rb:34:in `catch'
/gems/ruby/3.0.0/gems/warden-1.2.9/lib/warden/manager.rb:34:in `call'
/gems/ruby/3.0.0/gems/rack-2.2.4/lib/rack/tempfile_reaper.rb:15:in `call'
/gems/ruby/3.0.0/gems/rack-2.2.4/lib/rack/etag.rb:27:in `call'
/gems/ruby/3.0.0/gems/rack-2.2.4/lib/rack/conditional_get.rb:27:in `call'
/gems/ruby/3.0.0/gems/rack-2.2.4/lib/rack/head.rb:12:in `call'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_dispatch/http/permissions_policy.rb:22:in `call'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_dispatch/http/content_security_policy.rb:19:in `call'
/gems/ruby/3.0.0/gems/rack-2.2.4/lib/rack/session/abstract/id.rb:266:in `context'
/gems/ruby/3.0.0/gems/rack-2.2.4/lib/rack/session/abstract/id.rb:260:in `call'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_dispatch/middleware/cookies.rb:689:in `call'
/gems/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/migration.rb:601:in `call'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
/gems/ruby/3.0.0/gems/activesupport-6.1.6.1/lib/active_support/callbacks.rb:98:in `run_callbacks'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_dispatch/middleware/callbacks.rb:26:in `call'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_dispatch/middleware/executor.rb:14:in `call'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_dispatch/middleware/actionable_exceptions.rb:18:in `call'
/gems/ruby/3.0.0/gems/rollbar-3.3.1/lib/rollbar/middleware/rails/rollbar.rb:25:in `block in call'
/gems/ruby/3.0.0/gems/rollbar-3.3.1/lib/rollbar.rb:145:in `scoped'
/gems/ruby/3.0.0/gems/rollbar-3.3.1/lib/rollbar/middleware/rails/rollbar.rb:22:in `call'
/gems/ruby/3.0.0/gems/better_errors-2.9.1/lib/better_errors/middleware.rb:87:in `protected_app_call'
/gems/ruby/3.0.0/gems/better_errors-2.9.1/lib/better_errors/middleware.rb:82:in `better_errors_call'
/gems/ruby/3.0.0/gems/better_errors-2.9.1/lib/better_errors/middleware.rb:60:in `call'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_dispatch/middleware/debug_exceptions.rb:29:in `call'
/gems/ruby/3.0.0/gems/rollbar-3.3.1/lib/rollbar/middleware/rails/show_exceptions.rb:22:in `call_with_rollbar'
/gems/ruby/3.0.0/gems/web-console-4.2.0/lib/web_console/middleware.rb:132:in `call_app'
/gems/ruby/3.0.0/gems/web-console-4.2.0/lib/web_console/middleware.rb:28:in `block in call'
/gems/ruby/3.0.0/gems/web-console-4.2.0/lib/web_console/middleware.rb:17:in `catch'
/gems/ruby/3.0.0/gems/web-console-4.2.0/lib/web_console/middleware.rb:17:in `call'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
/gems/ruby/3.0.0/gems/railties-6.1.6.1/lib/rails/rack/logger.rb:37:in `call_app'
/gems/ruby/3.0.0/gems/railties-6.1.6.1/lib/rails/rack/logger.rb:26:in `block in call'
/gems/ruby/3.0.0/gems/activesupport-6.1.6.1/lib/active_support/tagged_logging.rb:99:in `block in tagged'
/gems/ruby/3.0.0/gems/activesupport-6.1.6.1/lib/active_support/tagged_logging.rb:37:in `tagged'
/gems/ruby/3.0.0/gems/activesupport-6.1.6.1/lib/active_support/tagged_logging.rb:99:in `tagged'
/gems/ruby/3.0.0/gems/railties-6.1.6.1/lib/rails/rack/logger.rb:26:in `call'
/gems/ruby/3.0.0/gems/ahoy_matey-4.1.0/lib/ahoy/engine.rb:22:in `call_with_quiet_ahoy'
/gems/ruby/3.0.0/gems/sprockets-rails-3.4.2/lib/sprockets/rails/quiet_assets.rb:13:in `call'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
/gems/ruby/3.0.0/gems/request_store-1.5.1/lib/request_store/middleware.rb:19:in `call'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_dispatch/middleware/request_id.rb:26:in `call'
/gems/ruby/3.0.0/gems/rack-2.2.4/lib/rack/method_override.rb:24:in `call'
/gems/ruby/3.0.0/gems/rack-2.2.4/lib/rack/runtime.rb:22:in `call'
/gems/ruby/3.0.0/gems/activesupport-6.1.6.1/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_dispatch/middleware/executor.rb:14:in `call'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_dispatch/middleware/static.rb:24:in `call'
/gems/ruby/3.0.0/gems/rack-2.2.4/lib/rack/sendfile.rb:110:in `call'
/gems/ruby/3.0.0/gems/actionpack-6.1.6.1/lib/action_dispatch/middleware/host_authorization.rb:148:in `call'
/gems/ruby/3.0.0/gems/railties-6.1.6.1/lib/rails/engine.rb:539:in `call'
/gems/ruby/3.0.0/gems/puma-5.6.4/lib/puma/configuration.rb:252:in `call'
/gems/ruby/3.0.0/gems/puma-5.6.4/lib/puma/request.rb:77:in `block in handle_request'
/gems/ruby/3.0.0/gems/puma-5.6.4/lib/puma/thread_pool.rb:340:in `with_force_shutdown'
/gems/ruby/3.0.0/gems/puma-5.6.4/lib/puma/request.rb:76:in `handle_request'
/gems/ruby/3.0.0/gems/puma-5.6.4/lib/puma/server.rb:441:in `process_client'
/gems/ruby/3.0.0/gems/puma-5.6.4/lib/puma/thread_pool.rb:147:in `block in spawn_thread'
allmarkedup commented 1 year ago

@Jackson200 sorry to take so long to get back to you on this - I don't yet have a fix I'm afraid (or even a solid grasp of what might be happening) but I just wanted to let you know it's still on my radar to look into more. Hope it's not too much of a blocker for you!

allmarkedup commented 1 year ago

Hey @Jackson200, I just wanted to let you know that Lookbook v2 (currently available as a beta) has got a completely reworked preview loading/updating system. If you are still using Lookbook and have a chance to give it a spin it would be great to know if you still encounter this issue or if it solves it for you :-)

allmarkedup commented 1 year ago

I'm going to close this down now but feel free to reopen if you find this issue is still happening in the v2 beta 👍

cabourn commented 3 months ago

For anyone seeing this issue I just had the same issue and tried adding paths to autoload_paths, etc. but still received the same error.

Realised I hadn't switched autoloader in Rails from :classic to the new default of :zeitwerk. This fixed it immediately.

allmarkedup commented 3 months ago

@cabourn okay great, glad you got it fixed and really appreciate you taking time to comment here to help others who come across the same issue.

Lookbook hasn't been tested with the classic autoloader still enabled so that makes sense.

Thanks again!