Skip to content

docs / when it breaks

Props that cannot cross

Errors and warnings when a Ruby value given to a component cannot be sent to the browser: a model without ruact_props, an object without as_json, an as_json that raises or returns itself.

request timeruact 0.0.22

When you finish

  • which Ruby values cross to a component as props, and which stop the page
  • why the same page can work in development and raise in production

Strings, numbers, booleans, nil, arrays and hashes of them cross to a component as they are. An object — a model, a PORO — crosses only as the fields it lists with Ruact::Serializable. These are the messages for everything else. The same four are raised for a server function’s JSON result, where they become a JSON 500 instead of an error page.

Ruact::SerializationErrorrequest · strict serialization

Cannot serialize Post — include Ruact::Serializable or set strict_serialization: false

Why. Strict serialization is on — the default in production — and the object only knows as_json, which would send every attribute it has.

Fix. List the fields that may leave the server:

app/models/post.rb
class Post < ApplicationRecord
include Ruact::Serializable
ruact_props :id, :title
end

With strict serialization off, the object crosses as its as_json instead, and the log warns, naming every attribute it sent:

[ruact] log warningrequest · strict serialization off

[ruact] WARNING: Post serialized via as_json — ALL attributes exposed to client: <attributes>. Use `include Ruact::Serializable` with `ruact_props` for explicit control

That is why a page can render in development and raise in production: the value never had ruact_props, and only production refused it.

Ruact::SerializationErrorrequest

Cannot serialize PriceQuote — include Ruact::Serializable

Fix. include Ruact::Serializable and ruact_props with its fields, or pass the values the component needs instead of the object.

Ruact::SerializationErrorrequest · strict serialization off

Post#as_json raised NoMethodError: <the error's message>

Ruact::SerializationErrorrequest · strict serialization off

PriceQuote#as_json returned self — would cause infinite recursion. Include Ruact::Serializable and declare ruact_props instead

ruact_props names a method that does not exist

Section titled “ruact_props names a method that does not exist”

ArgumentErrorclass load (PORO) · first render (Active Record model)

ruact_props: method `subtitle` is not defined on Post

Fix. Check the spelling in ruact_props, or define the method.