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

[Admin] Add stock_items/edit modal component #5543

Merged
merged 9 commits into from
Dec 12, 2023
Prev Previous commit
Next Next commit
Enable logging for view components
This initializer configures logging for View Components.
In the development and test environments, it subscribes
to the 'render.view_component' event, and logs the
rendered component's name and duration in milliseconds.

https://viewcomponent.org/guide/instrumentation.html#viewing-instrumentation-sums-in-the-browser-developer-tools

Co-Authored-By: Elia Schito <[email protected]>
  • Loading branch information
rainerdema and elia committed Dec 11, 2023
commit 6383bccc24442d5810d39163608a20d7559f3465
20 changes: 20 additions & 0 deletions admin/config/initializers/view_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

Rails.application.config.view_component.capture_compatibility_patch_enabled = true

if Rails.env.development? || Rails.env.test?
Rails.application.config.view_component.instrumentation_enabled = true
Rails.application.config.view_component.use_deprecated_instrumentation_name = false

bold = ActiveSupport::LogSubscriber::BOLD
clear = ActiveSupport::LogSubscriber::CLEAR

ActiveSupport::Notifications.subscribe("render.view_component") do |*args|
next unless args.last[:name].starts_with?("SolidusAdmin::")

event = ActiveSupport::Notifications::Event.new(*args)
SolidusAdmin::BaseComponent.logger.debug \
" Rendered #{bold}#{event.payload[:name]}#{clear}" \
" (Duration: #{event.duration.round(1)}ms)"
end
end