Configuration
ReactiveComponent exposes a handful of configuration options. You can set them in an initializer (e.g. config/initializers/reactive_component.rb).
ReactiveComponent.debug
Section titled “ReactiveComponent.debug”Enables debug mode. Defaults to false.
ReactiveComponent.debug = Rails.env.development?When enabled:
- Unencoded templates — Compiled JavaScript templates are embedded as plain text instead of Base64-encoded strings, making them easier to inspect in the browser.
- Debug wrapper divs — Each reactive component’s wrapper
<div>receives adata-reactive-debugattribute with a human-readable label (e.g."Message row component #message_42") and areactive-debug-wrapperCSS class so you can visually identify reactive components during development.
ReactiveComponent.renderer
Section titled “ReactiveComponent.renderer”Sets the renderer used when evaluating nested component render calls during data extraction. Defaults to nil, which falls back to ActionController::Base.
ReactiveComponent.renderer = ApplicationControllerThis is useful if your components call render for nested ViewComponents and the rendering requires application-specific route helpers or configuration that ActionController::Base does not provide.
ReactiveComponent::Channel.compress
Section titled “ReactiveComponent::Channel.compress”Enables gzip compression for ActionCable broadcasts. Defaults to false.
ReactiveComponent::Channel.compress = trueWhen enabled, broadcast payloads are JSON-encoded, gzip-compressed, and Base64-encoded before being sent over ActionCable. The client-side Stimulus controller automatically detects and decompresses these payloads. This can significantly reduce bandwidth for components with large data payloads.
ReactiveComponent::Channel.filter_callback
Section titled “ReactiveComponent::Channel.filter_callback”Sets a callback for filtering whether a record matches the current subscription parameters. Defaults to nil (no filtering — all records on the stream are accepted).
ReactiveComponent::Channel.filter_callback = ->(record, params) { # Only re-render if the record belongs to the requested category params["category_id"].blank? || record.category_id.to_s == params["category_id"]}The callback receives two arguments:
| Argument | Description |
|---|---|
record | The ActiveRecord model instance being broadcast |
params | A hash of subscription parameters sent by the client |
Return true to allow the component to re-render with this record, or false to skip it. When false is returned on an update request, the channel transmits a "remove" action instead, causing the client to remove the component from the DOM.
Full example
Section titled “Full example”ReactiveComponent.debug = Rails.env.development?ReactiveComponent.renderer = ApplicationController
ReactiveComponent::Channel.compress = Rails.env.production?ReactiveComponent::Channel.filter_callback = ->(record, params) { true # accept all by default}