{"record":{"id":"3bf1c4e7c2b583eb","repo":"ViewComponent/view_component","slug":"cannot-serialize-render-in-with-a-block","errorCode":null,"errorMessage":"Cannot serialize render_in with a block","messagePattern":"Cannot serialize render_in with a block","errorType":"exception","errorClass":"ViewComponent::Serializable::UnserializableError","httpStatus":null,"severity":"error","filePath":"lib/view_component/serializable/proxy.rb","lineNumber":44,"sourceCode":"      end\n\n      attr_reader :component_class, :initialize_args, :slot_calls\n\n      def initialize(component_class, *args)\n        if component_class.name.nil?\n          raise UnserializableError, \"Cannot serialize anonymous component class #{component_class.inspect}\"\n        end\n\n        @component_class = component_class\n        @initialize_args = args\n        @slot_calls = []\n      end\n      ruby2_keywords :initialize\n\n      # Implements the Rails renderable interface\n      def render_in(view_context, &block)\n        if block\n          raise UnserializableError, \"Cannot serialize render_in with a block\"\n        end\n        build_component.render_in(view_context)\n      end\n\n      def method_missing(method_name, *args, &block)\n        if slot_method?(method_name)\n          capture_slot_call(method_name, args, &block)\n        else\n          super\n        end\n      end\n      ruby2_keywords :method_missing\n\n      def respond_to_missing?(method_name, include_private = false)\n        slot_method?(method_name) || super\n      end\n\n      # Returns a hash that can be rebuilt into a Proxy instance using +deserialize+","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/ViewComponent/view_component/blob/9f22c36fa7d7b44098a8ed97472e3b4674ae420f/lib/view_component/serializable/proxy.rb#L26-L62","documentation":"The Proxy returned by render_later implements the Rails renderable interface via render_in, but the whole point of the proxy is that it can be serialized — and blocks can't be. If render_in is called with a block (e.g., render(proxy) { ... } in a template, or broadcast-style calls that capture a block), it raises ViewComponent::Serializable::UnserializableError ('Cannot serialize render_in with a block') before building the component. Content data must be attached beforehand via with_* slot calls that take arguments only.","triggerScenarios":"<%= render(MyComponent.render_later(\"x\")) do %>Block<% end %> in an ERB template; passing a content block when broadcasting a deferred component with Turbo Streams; generic code that always yields a block to any renderable object it renders.","commonSituations":"Swapping a live component for a deferred proxy in an existing template that still has a block; helper methods that render arbitrary renderables with an optional block; migrating broadcast calls to the proxy API.","solutions":["Remove the block from the render call: <%= render(MyComponent.render_later(\"x\")) %>.","Supply the would-be block content as slot arguments instead: render(MyComponent.render_later(\"x\").with_body(\"<p>content</p>\")) using a slot the component renders.","If the block genuinely needs the render-time view context, render the concrete component (MyComponent.new(...)) rather than the proxy."],"exampleFix":"# before (ERB)\n<%= render(MyComponent.render_later(\"title\")) do %>\n  <p>Block content</p>\n<% end %>\n\n# after (ERB)\n<%= render(MyComponent.render_later(\"title\").with_body(\"<p>Block content</p>\")) %>","handlingStrategy":"validation","validationCode":"def render_deferred(view_context, proxy, &block)\n  raise ArgumentError, \"proxies cannot render with a block\" if block\n  view_context.render(proxy)\nend","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Render proxies block-free: <%= render(proxy) %> with all data attached via with_* calls beforehand.","Standardize a helper (e.g., render_deferred) that forbids blocks so misuse fails at the call site."],"tags":["view-component","ruby-on-rails","serialization","render-in","turbo-streams"],"backgroundTag":"block-not-serializable","analyzedSha":"9f22c36fa7d7b44098a8ed97472e3b4674ae420f","analyzedAt":"2026-08-23T10:20:47.008Z","schemaVersion":2},"datasetVersion":"2026-08-23T13:39:53.451Z"}