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.
A model without ruact_props
Section titled “A model without ruact_props”Cannot serialize Post — include Ruact::Serializable or set strict_serialization: falseWhy. 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:
class Post < ApplicationRecord include Ruact::Serializable ruact_props :id, :titleendWith strict serialization off, the object crosses as its as_json instead, and the log warns, naming every attribute it sent:
[ruact] WARNING: Post serialized via as_json — ALL attributes exposed to client: <attributes>. Use `include Ruact::Serializable` with `ruact_props` for explicit controlThat is why a page can render in development and raise in production: the value never had ruact_props, and only production refused it.
An object without as_json
Section titled “An object without as_json”Cannot serialize PriceQuote — include Ruact::SerializableFix. include Ruact::Serializable and ruact_props with its fields, or pass the values the component needs instead of the object.
An as_json that raises
Section titled “An as_json that raises”Post#as_json raised NoMethodError: <the error's message>An as_json that returns the object itself
Section titled “An as_json that returns the object itself”PriceQuote#as_json returned self — would cause infinite recursion. Include Ruact::Serializable and declare ruact_props insteadruact_props names a method that does not exist
Section titled “ruact_props names a method that does not exist”ruact_props: method `subtitle` is not defined on PostFix. Check the spelling in ruact_props, or define the method.